2014-03-19 66 views
1

進出口使用nginx的一個非常簡單的配置,它適用於在/ usr /共享/ nginx的/網絡/的子目錄所有PHP網站。Nginx的 - 重寫或內部重定向循環

但現在我還想建立一個新的項目與重寫規則的子目錄。 所以,我決定做一個的.conf這個默認的旁邊。 但重寫不正常的錯誤原因「改寫或內部重定向循環」。

默認

server { 
    listen 80 default_server; 
    # listen [::]:80 default_server ipv6only=on; 

    root /usr/share/nginx/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 displaying a 404. 
      try_files $uri $uri/ /index.html; 
      # Uncomment to enable naxsi on this location 
      # include /etc/nginx/naxsi.rules 
    } 

    location /doc/ { 
      alias /usr/share/doc/; 
      autoindex on; 
      allow 127.0.0.1; 
      allow ::1; 
      deny all; 
    } 

    location ~ \.php$ { 
      try_files $uri =404; 
      # fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 

      # With php5-cgi alone: 
      # fastcgi_pass 127.0.0.1:9000; 
      # With php5-fpm: 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
      fastcgi_intercept_errors on; 
    } 

    location ~ /\. { 
      access_log off; 
      log_not_found off; 
      deny all; 
    } 
} 

newproject.conf

# nginx configuration 
autoindex off; 

location /newproject/ { 
    if (!-e $request_filename) { 
      rewrite ^/newproject/(.+)$ /newproject/index.php?url=$1 break; 
    } 
} 

回答

0
 # First attempt to serve request as file, then 
     # as directory, then fall back to displaying a 404. 
     try_files $uri $uri/ /index.html; 

這部分大約回落至404是錯誤的。也許你已經錯過=404在這裏,這導致重定向循環(它重定向到/index.html一遍又一遍)。

請注意,從the documentation

如果發現沒有任何文件的,內部重定向到最後一個參數指定的URI而成。

即使try_files $ URI $ URI/= 404
+0

;我在日誌中得到相同的錯誤。 – Mav