2011-05-04 31 views
0

我有下/path/nginx的重写 - 文件存在,但被重写需要

一切的PHP应用程序不存在(文件/目录)将被重定向到/path/index.php

if (!-e $request_filename) 
{ 
    rewrite ^/path/(.+)$ /path/index.php last; 
} 

和一切正常开从实际的文件,因为某些原因的.css存在仍然重定向到索引文件......如/path/CSS/style.css

UPDATE

固定rewrite ^/path/(.+)/$ /path/index.php last;,因为我的所有URL需要重写末尾必须有斜线,但仍扑朔迷离

nginx.conf

http { 
include  /etc/nginx/mime.types; 
access_log /var/log/nginx/access.log; 

sendfile  on; 

keepalive_timeout 65; 
tcp_nodelay  on; 

gzip on; 
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 

include /etc/nginx/conf.d/*.conf; 
include /etc/nginx/sites-enabled/*; 
} 

全面启用站点/文件

server { 
    listen valueyourvote.org.nz:80; 
    server_name valueyourvote.org.nz valueyourvote.co.nz; 

    if ($http_host != www.valueyourvote.org.nz) { 
     rewrite (.*) http://www.valueyourvote.org.nz$1; 
    } 
    access_log /var/log/nginx/valueyourvote.org.nz.access.log; 
    error_log /var/log/nginx/valueyourvote.org.nz.error.log; 
    location/{ 
    root /var/www/vote.incode.co.nz/; 
    index index.php index.html index.htm; 
    } 

    if (!-e $request_filename) 
    { 
    rewrite ^/supercity-2010/(.+)/$ /supercity-2010/index.php last; 
    } 


    # Pass all .php files onto a php-fpm/php-fcgi server. 
    location ~ \.php$ { 
    fastcgi_pass localhost:9000; 
    fastcgi_index index.php; 

    include fastcgi_params; 
    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    location ~ /\.ht { 
    deny all; 
    } 
} 

回答

2

您应该避免使用nginx的在“如果”只要有可能 - 见"If is evil"在nginx的维基。为了您的使用,更好的使用指令是try_files

至于指令不工作,你是你的“根”指令的范围之外测试的文件 - 即nginx的不知道去哪里找,看看这些URI是文件!

将一个try_files指示您的位置块内,并应工作。

+0

我想'try_files'基于信息在这里http://michaelshadle.com/2009/03/19/finally-using-nginxs-try-files-directive但它并没有帮助,也许在配置的其他地方会出现一些奇怪的现象,但它只是在Ubuntu的基础上安装的,所以它们应该没问题 – 2011-05-04 21:59:28

+0

如果你可以提供更多的nginx配置,也许我们可以找到bug :) – ZoFreX 2011-05-04 22:05:31

+0

添加配置文件 – 2011-05-04 23:04:00

0

你可以这样做

location [your_location]{ 
    try_files $uri $uri/ @w; 
} 
location @w { 
rewrite ^/path/(.+)$ /path/index.php last; 
}