【发布时间】:2016-02-22 07:10:27
【问题描述】:
我正在尝试使用 Nginx 将 url 重写为更加用户友好。删除 index.php?r= 是成功的,但问题是,在我尝试访问其他页面后,它显示 404 Not Found。我已经在config/web 中添加了 urlmanager 以获得漂亮的 url,但它不起作用。有人可以帮我弄这个吗?
我会尝试发布代码。
这是 nginx.conf
server {
listen 88;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
rewrite ^(.*[^/])$ $1/ permanent;
try_files $uri $uri/ /index.php?r=$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
include fastcgi_params;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
这是网址管理器。
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
我首先在本地主机上尝试了这个。
谢谢。
【问题讨论】:
-
我认为你必须将根路径作为 root
/var/www/html/yii-app/web;而不是html; -
@Selvakumar 当我按照您的建议将根 html 从
html更改为/html/yii-app/web时,这是我在 error.log 中遇到的错误。2016/02/23 10:13:53 [error] 3116#1344: *2 "C:/html/MAPUser/web/MAPUser/web/index.php" is not found (3: The system cannot find the path specified)我将我的 nginx 放在 C 中: