芦苇vip 2019-12-17 11:04:39 1015次浏览 2条评论 7 7 0

修改 Nginx 配置

server
{
    listen 80;
    #listen [::]:80;
    server_name local.yii2.com ;
    #error_page   404   /404.html;
    location / {
        root /home/wwwroot/yii2/html;
        try_files $uri $uri/ =404;
        index index.html;
    }
    location /admin/ {
        alias /home/wwwroot/yii2/backend/web/;
        index index.php;
        try_files $uri /index.php/admin$is_args$args;
    }
    location ~ [^/]\.php/admin(/|$) {
            alias /home/wwwroot/adnonstop-21camera/backend/web;
            fastcgi_pass unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            include pathinfo.conf;
            fastcgi_param SCRIPT_NAME /admin$fastcgi_script_name;
    }
    access_log  /home/wwwlogs/local.yii2.com.access_log;
    error_log /home/wwwlogs/local.yii2.com.error_log;
}

http://local.yii2.com/ 访问官网
http://local.yii2.com/admin 访问后台

核心配置是:fastcgi_param SCRIPT_NAME /admin$fastcgi_script_name; Yii2 的框架会以 /admin 作为脚本运行的目录,可参考 yii\web\Request::getScriptUrl 方法。

觉得很赞
亿速云
您需要登录后才可以评论。登录 | 立即注册