首頁 >後端開發 >php教程 >nginx的location怎么设置匹配前后台地址?

nginx的location怎么设置匹配前后台地址?

WBOY
WBOY原創
2016-06-06 20:16:431589瀏覽

我的配置:

<code>server {
listen      80;
server_name     www.xxx.com xxx.com;



# server_name_in_redirect off;

root  /alidata/www/default/yooao/frontend/web;

location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
   }

location / {
index index.php ;
root  /alidata/www/default/yooao/frontend/web;
}

location ~ ^/backend$ {
index index.php ;
root  /alidata/www/default/yooao/backend/web;
}

}</code>

现在是前台可以进去,后台却不对,我用的是yii2框架。之前没加

<code>`location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
   }`</code>

时进前台首页会变成下载页面。现在我想匹配url进后台不知道该怎么做了,现在进后台www.xxx.com/backend显示404,新手求指教

回复内容:

我的配置:

<code>server {
listen      80;
server_name     www.xxx.com xxx.com;



# server_name_in_redirect off;

root  /alidata/www/default/yooao/frontend/web;

location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
   }

location / {
index index.php ;
root  /alidata/www/default/yooao/frontend/web;
}

location ~ ^/backend$ {
index index.php ;
root  /alidata/www/default/yooao/backend/web;
}

}</code>

现在是前台可以进去,后台却不对,我用的是yii2框架。之前没加

<code>`location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
   }`</code>

时进前台首页会变成下载页面。现在我想匹配url进后台不知道该怎么做了,现在进后台www.xxx.com/backend显示404,新手求指教

  1. 官网文档明确给出如何配置 nginx,地址是:http://www.getyii.com/doc-2.0/guide/start-installation.html#nginx

  2. 如果你使用的是高级版,项目初始化完成之后,frontend,backend 需要分别配置,即要配置两个vhost

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn