CakePHP 2.x 版本的部署,BASE URL 调整的实现(/ -> /creditshopback)

1、当前的 BASE URL 为 /,https://creditshopback.xxx.cn/ 。响应 200。如图1

当前的 BASE URL 为 /,https://creditshopback.xxx.cn/ 。响应 200。

图1

2、编辑程序文件,输出当前的版本号为:2.6.4。如图2

编辑程序文件,输出当前的版本号为:2.6.4。

图2

echo Configure::version();
exit;

3、现在期望网址调整为:https://console.xxx.cn/creditshopback 。参考开发安装方式:https://book.cakephp.org/2/zh/installation.html 。如图3

现在期望网址调整为:https://console.xxx.cn/creditshopback 。参考开发安装方式:https://book.cakephp.org/2/zh/installation.html 。

图3

4、查看现阶段的 Nginx 配置

server {
    listen 82;
    charset utf-8;
    
    root /mcloud/creditshop_back/app/webroot;
    index index.php;

    location / {
        # modsecurity on;
        # modsecurity_rules_file /etc/nginx/modsec_includes_lite.conf;
        if (!-e $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
        }
    }

    location /creditf {
        # modsecurity on;
        # modsecurity_rules_file /etc/nginx/modsec_includes_lite.conf;
        alias /webtv/wangjie/creditshop_back/h5jifen/files;
        index index.html;
    }

    location /upload {
        alias /webtv/wangjie/creditshop_back/upload;
        index index.html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ /.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /mcloud/creditshop_back/app/webroot$fastcgi_script_name;
        include        fastcgi_params;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ //.ht {
        deny  all;
    }
}

5、剪切目录:/mcloud/creditshop_back/* 至 /mcloud/creditshop_back/creditshopback/*。如图4

剪切目录:/mcloud/creditshop_back/* 至 /mcloud/creditshop_back/creditshopback/*。

图4

6、编辑 Nginx 配置

server {
    listen 82;
    charset utf-8;

    root /mcloud/creditshop_back/;
    index index.php;

    location / {
        # modsecurity on;
        # modsecurity_rules_file /etc/nginx/modsec_includes_lite.conf;
        if (!-e $request_filename) {
            rewrite ^/(.+)$ /index.php?url=$1 last;
            break;
        }
    }

    location /creditshopback/creditf {
        # modsecurity on;
        # modsecurity_rules_file /etc/nginx/modsec_includes_lite.conf;
        alias /webtv/wangjie/creditshop_back/h5jifen/files;
        index index.html;
    }

    location /creditshopback/upload {
        alias /webtv/wangjie/creditshop_back/upload;
        index index.html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ /.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /mcloud/creditshop_back/$fastcgi_script_name;
        include        fastcgi_params;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ //.ht {
        deny  all;
    }
}

7、响应中存在 404。其网址:https://console.xxx.cn/creditshopback/css/common.css 。需要调整为:https://console.xxx.cn/creditshopback/app/webroot/css/common.css 。如图5

响应中存在 404。其网址:https://console.xxx.cn/creditshopback/css/common.css 。需要调整为:https://console.xxx.cn/creditshopback/app/webroot/css/common.css 。

图5

8、在目录:/app/View 中批量替换 echo $this->Html->css(‘ 为 echo $this->Html->css(‘/app/webroot/css/。类似于 echo $this->Html->css(‘cake.generic’); 的不做替换。如图6

在目录:/app/View 中批量替换 echo $this->Html->css(' 为 echo $this->Html->css('/app/webroot/css/。类似于 echo $this->Html->css('cake.generic'); 的不做替换。

图6

9、在目录:/app/View 中批量替换 echo $this->Html->script(‘ 为 echo $this->Html->script(‘/app/webroot/js/。类似于 echo $this->Html->css(‘cake.generic’); 的不做替换。

10、响应中不存在 404。https://console.xxx.cn/creditshopback/app/webroot/css/common.css 。响应 200。如图7

响应中不存在 404。https://console.xxx.cn/creditshopback/app/webroot/css/common.css 。响应 200。

图7

11、打开网址:https://console.xxx.cn/creditshopback/products/AddNewProduct?tenantid=2a20ea857030b75d3efa343cd625ee03 。响应 404。

12、参考网址:https://www.shuijingwanwq.com/2018/08/16/2836/ 。编辑 Nginx 配置

server {
    listen 82;
    charset utf-8;

    root /mcloud/creditshop_back;
    index index.php;

    location /creditshopback {
        alias /mcloud/creditshop_back/creditshopback/app/webroot/;
        location = /creditshopback {
            try_files $uri /creditshopback/creditshopback/app/webroot/index.php$is_args$args;
        }
        try_files $uri $uri/ /creditshopback/creditshopback/app/webroot/index.php$is_args$args;
    }

    location /creditshopback/creditf {
        # modsecurity on;
        # modsecurity_rules_file /etc/nginx/modsec_includes_lite.conf;
        alias /webtv/wangjie/creditshop_back/h5jifen/files;
        index index.html;
    }

    location /creditshopback/upload {
        alias /webtv/wangjie/creditshop_back/upload;
        index index.html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ ^/.+/.php(/|$) {
        rewrite (?!^/creditshopback/app/webroot)^/creditshopback(/.+)$ /creditshopback/app/webroot$1 break;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        try_files      $fastcgi_script_name =404;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ //.ht {
        deny  all;
    }
}

13、打开网址:https://console.xxx.cn/creditshopback/products/AddNewProduct?tenantid=2a20ea857030b75d3efa343cd625ee03 。响应 200。

14、还原第 8、9 步骤。最终结果全部响应 200,符合预期。

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250660.html

(0)
上一篇 2022年5月1日
下一篇 2022年5月1日

相关推荐

发表回复

登录后才能评论