没有不值得去解决的问题,也没有不值得去学习的技术!

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

响应中不存在 404。https://console.xxx.cn/creditshopback/app/webroot/css/common.css 。响应 200。
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,符合预期。

需要长期技术维护或远程问题排查?

我是拥有 15+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理