如何让yii在nginx的子目录下支持rewrite?
我试图这样去尝试
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
结果img js css都显示不出来,不知道什么原因?
nginx nginx/0.8.54
配置如下:
location / {
root /home/html/;
index index.php index.html index.htm index.shtml;
}
location ~ \.php$ {
root /home/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/html$fastcgi_script_name;
include fastcgi_params;
}
另外找到这篇文章,但这种方式是绑定新domain!
http://www.yiiframework.com/wiki/153/using-yii-with-nginx
Leric
(Leric Zhang)
March 16, 2011, 10:38am
2
试试在这个location设置里加上个root
location /blog {
root /path/to/blog;
try_files $uri $uri/ /index.php?$args;
}
加了也是一样!
location /blog {
try_files $uri $uri/ /index.php?$args;
}
加上这个之后 页面是可以访问的! 不会出现 404
但是对于所有的文件请求也被当作get的参数去执行了
比如说打开这个
http://localhost/blog/css/main.css
结果就会出现
Error 404
Unable to resolve the request "css/main.css".
到底是什么原因呢?有没有朋友遇到过类似情况?请教应该如何配置呢?
wwwwwgq
(Wgq91here)
March 17, 2011, 2:50am
4
看我的配置。
location /
{
# If the file exists as a static file serve it
# directly without running all
# the other rewite tests on it
if ($request_filename ~ “favicon\.ico$”) {
break;
}
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
break;
}
}
解决了,顺便整理了下!
nginx version 0.8.54
server {
...
root /home/html/;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
location /blog {
try_files $uri $uri/ /index.php?$args; #此处应该是$args 不应该是 $request_uri 看到有一文章这里用的是 $request_uri
}
...
}