2012-01-07 194 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;