2012-05-21 70 views
2

我想訪問該網址後:斜線論據Nginx的,PHP

http://test/symfony/web/app_dev.php/ 

但它不會工作,因爲結尾的斜線的,我得到一個404

這些那些做工精細:

http://test/symfony/web/app_dev.php 
http://test/symfony/web/app_dev.php?/ 

在Apache中,/app_dev.php/something和/app_dev.php?/something是相同的。關於如何在Nginx中實現這個工作的任何想法?

我嘗試添加一個重寫,沒有運氣:

location/{ 
      try_files $uri $uri/ @rewrite index.html; 
    } 

    location @rewrite { 
      rewrite ^/(.*\.php)/(.*)$ $1?/$2; 
    } 

回答

1

這是我工作得很好:

location/{ 
      # Remove app.php from url, if somebody added it (doesn't remove if asked for /app.php on the root) 
      rewrite ^/app\.php/(.*) /$1 permanent; 

      try_files $uri $uri/ /app.php?$query_string; 
    } 

    location ~ \.php$ { 
      try_files $uri = 404; 
      # Below is for fastcgi: 
      # fastcgi_pass 127.0.0.1:9000; 
      # fastcgi_index app.php; 
      # include   /etc/nginx/fastcgi_params; 
      # fastcgi_param SCRIPT_FILENAME /mnt/www/live/current/web$fastcgi_script_name; 
      # fastcgi_param SERVER_PORT 80; 
      # fastcgi_param HTTPS off; 
    } 
+0

try_files行應該是'try_files $ uri = 404'而不是'try_files $ uri = 404'。額外的空間會讓nginx尋找'$ document_root $ uri','$ document_root =','$ document_root404' – zhangyoufu

0

我終於跨過這對我的作品的答案跌跌撞撞:

location ~ /directory/(.*\.php)(/.*)$ { 
      set $script_filename $1; 
      set $path_info $2; 
      fastcgi_param PATH_INFO  $2; 
      alias /place/directory/$1; 
      include fastcgi_params; 

https://github.com/plack/Plack/issues/281

以下是文檔中的相關片段:請注意,它們都不使用nginx提供的用於script_name或path_info的FCGI參數,因爲它被稱爲不正確。

location/{ 
set $script ""; 
set $path_info $uri; 
fastcgi_pass unix:/tmp/fastcgi.sock; 
fastcgi_param SCRIPT_NAME  $script; 
fastcgi_param PATH_INFO  $path_info;