2012-01-07 157 views
0

只需执行一个Nginx,PHP的安装,然后tutorial,一切正常。 输入网址http://192.168.1.10显示欢迎画面。nginx与重写

server { 
     listen 80; ## listen for ipv4; this line is default and implied 
     listen [::]:80 default ipv6only=on; ## listen for ipv6 

     #root /usr/share/nginx/www; 
     root /var/www/; 
     index index.php index.html index.htm; 

     # Make site accessible from http://localhost/ 
     server_name localhost; 

     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to index.html 
       #try_files $uri $uri/ /index.html; 
     } 

     location /test{ 
       if (-f $request_filename) { 
         break; 
       } 
       if (-d $request_filename) { 
         break; 
       } 
       rewrite ^(.+)/$ /index.php?x=$1 last; 
     } 

     location /doc { 
       root /usr/share; 
       autoindex on; 
       allow 127.0.0.1; 
       deny all; 
     } 

     location /images { 
       root /usr/share; 
       autoindex off; 
     } 
     #error_page 404 /404.html; 

     # redirect server error pages to the static page /50x.html 
     # 
     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
       root /usr/share/nginx/www; 
     } 

     # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
     # 
     #location ~ \.php$ { 
     #  proxy_pass http://127.0.0.1; 
     #} 

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
     # 
     location ~ \.php$ { 
       fastcgi_pass unix:/tmp/php5-fpm.sock; 
       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; 
     } 
} 

预期它不工作: 现在在进入http://192.168.1.10/test/my-test/电话index.php?x=my-test

修改后的sites-avaible/default看起来像这样创建一个名为test文件夹,要实现类似阿帕奇国防部重写,这样。如果我去http://192.168.1.10/test/my-test/会发生什么情况,它显示http://192.168.1.10/索引的值。

Attached image

+0

任何帮助或想法? – Alexd2 2012-01-08 18:31:45

回答

1

可能是你可以试试这个:一旦达到的index.php正确格式化

try_files $uri $uri/ /index.php?q=$uri&$args; 

Zend框架将在其约定转换参数。

+0

我见过很多添加'q = $ uri'的例子,但我不明白为什么人们设置这个变量。出于其他原因,您最好永远不要有一个页面需要'q'变量。否则,事情可能会变得混乱!我宁愿使用:'try_files $ uri $ uri//index.php?$ args;' – Maxime 2012-03-21 13:33:59

1

使用此重写规则: rewrite /test/(.*)/index.php?x=$1 last;