2013-08-19 84 views
3

我在Raspbian wheezy上有nginx 1.2.1-2.2的問題。我認爲它是在我的sites-available/default文件中更改索引之後開始的。以下是相關文件:Nginx'重寫或內部重定向週期,同時內部重定向'導致500

nginx.conf 
user www-data; 
worker_processes 4; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 768; 
    # multi_accept on; 
} 

http { 

    ## 
    # Basic Settings 
    ## 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 
    index index.html index.htm index.php; 
    # server_tokens off; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect off; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    ## 
    # Logging Settings 
    ## 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    ## 
    # Gzip Settings 
    ## 

    gzip on; 
    gzip_disable "msie6"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 

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

sites-available/default 

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

    root /home/tom/www; 
    index index.html index.htm index.php; 

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

    try_files $uri $uri/ /index.html =404; 

    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 /yourls { 
    # YOURLS time 
    if (!-e $request_filename){ 
     rewrite ^(.*)$ /yourls-loader.php break; 
    } 
    } 

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests 
    #location /RequestDenied { 
    # proxy_pass http://127.0.0.1:8080;  
    #} 

    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; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
     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; 
     include fastcgi_params; 
    } 
} 

我正在試圖訪問WordPress的任何頁面時,包括剛纔輸入local.dyn.kwl.me/wordpress/到地址欄或添加錯誤index.php或wp-admin到該URL。在瀏覽器中會顯示爲500,但nginx的日誌中這樣說:

2013/08/19 17:55:49 [error] 31600#0: *58 rewrite or internal redirection cycle while internally redirecting to "/wordpress/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html", client: 109.149.13.53, server: localhost, request: "GET /wordpress HTTP/1.1", host: "local.dyn.kwl.me" 
2013/08/19 17:55:49 [error] 31600#0: *59 rewrite or internal redirection cycle while internally redirecting to "/favicon.ico/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html", client: 109.149.13.53, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "local.dyn.kwl.me" 

我想像的東西是錯誤的,在我的網站,默認的文件索引或try_files。任何人都能看到什麼?

+0

什麼位置/ YOURLS指什麼?您是否使用domain.com/yourls訪問您的Wordpress網站? –

+1

爲什麼在一個位置塊之外有一個try_files? – Danack

+0

我在magento網站上也收到此錯誤 – ShaunOReilly

回答

9

我運行Nginx的WordPress網站很多。如果你可以使用它們,這裏是位置指令的部分成功配置。 Nginx版本是1.0.15。您可能需要更改fastcgi_pass param以運行您的fastcgi_wrapper運行的任何內容。也許fastcgi_pass 127.0.0.1:9000

location @php { 
     try_files $uri =404; 
     include /etc/nginx/fastcgi_params; 
     fastcgi_pass 127.0.0.1:9090; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
    } 

    if (!-e $request_filename){ 
      rewrite ^(.*)$ /index.php?q=$1 last; 
      break; 
    } 

所以,在你的網站配置

sites-available/default 

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

    root /home/tom/www; 
    index index.html index.htm index.php; 

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


    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests 
    #location /RequestDenied { 
    # proxy_pass http://127.0.0.1:8080;  
    #} 

    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; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    ## Original Config 
    # location ~ \.php$ { 
    # 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; 
    # include fastcgi_params; 
    # } 

    ## New Config 
    location @php { ## Depending on your Nginx version, you might need to change this to location ~ \.php$ { 
     try_files $uri =404; 
     include /etc/nginx/fastcgi_params; 
     fastcgi_pass 127.0.0.1:9090; ## Maybe change to 9000 or use socket fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
    } 

    ## Wordpress Rewrite 
    if (!-e $request_filename){ 
      rewrite ^(.*)$ /index.php?q=$1 last; 
      break; 
    } 

} 

編輯

基於你對我說的最後意見。如果您的DNS沒有解析到子目錄/ wordpress /那麼您必須更改您的重寫規則。

## Wordpress Rewrite 
    if (!-e $request_filename){ 
      rewrite ^(.*)$ /wordpress/index.php?q=$1 last; 
      break; 
    } 
+0

現在WordPress(仍然沒有其他目錄有任何問題)正在下載名爲'download'的文件,其中包含index.php的內容。我很困惑:/我正在使用你發佈的配置,使用'location〜\ .php $',並使用套接字而不是本地IP和端口作爲php5-fpm。 –

+0

它試圖下載文件,因爲您沒有將請求傳遞給PHP,因此我認爲您的fastcgi_pass配置可能是錯誤的。如果它在'unix:/var/run/php5-fpm.sock;' –

+0

之前工作,請嘗試使用此fastcgi_pass fastcgi_pass嗯,/ yourls-next(php腳本)和/ wordpress/wp-admin都能正常工作。這只是/ wordpress即時生成下載文件。 /wordpress/index.php需要一段時間,但仍然要求我下載該文件。我試過禁用WordPress重寫規則,但是對任何事情都沒有影響。我可能會嘗試重新安裝WordPress。配置中沒有任何內容專門針對WordPress的前端。 –

0

你有沒有試過類似的東西? (具體以Magento的可能)

server { 
     listen 80 default; 
     ssl off; 
     root /var/www/magento; 
     server_name mydomain.com.au; 
     location/{ 
      index index.html index.php; 
      try_files $uri $uri/ @handler; 
      expires 30d; 
     } 
     location ^~ /app/ { deny all; } 
     location ^~ /includes/ { deny all; } 
     location ^~ /lib/ { deny all; } 
     location ^~ /media/downloadable/ { deny all; } 
     location ^~ /pkginfo/ { deny all; } 
     location ^~ /report/config.xml { deny all; } 
     location ^~ /var/ { deny all; } 
     location /var/export/ { ## Allow admins only to view export folder 
      auth_basic "Restricted"; ## Message shown in login window 
      auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword 
      autoindex on; 
     } 
     location /. { ## Disable .htaccess and other hidden files 
      return 404; 
     } 
     location @handler { ## Magento uses a common front handler 
      rewrite//index.php; 
     } 
     location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler 
      rewrite ^(.*.php)/ $1 last; 
     } 
     location ~ .php$ { ## Execute PHP scripts 
      if (!-e $request_filename) { rewrite//index.php last; } 
      expires off; ## Do not cache dynamic content 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_param HTTPS $fastcgi_https; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      fastcgi_param MAGE_RUN_CODE default; 
      fastcgi_param MAGE_RUN_TYPE store; 
      include fastcgi_params; 
     }   
    } 

server { 
     listen 443; 
     ssl on; 
     ssl_certificate /etc/ssl/certs/mydomain_com_au.crt; 
     ssl_certificate_key /etc/ssl/private/mydomain_com_au.key; 
     ssl_client_certificate /etc/ssl/crt/mydomain_com_au.crt; 
     access_log /var/log/nginx/mydomain.ssl.access.log; 
     error_log /var/log/nginx/mydomain.ssl.error.log; 
     server_name mydomain.com.au; 
     root /var/www/magento; 
     location/{ 
      index index.html index.php; 
      try_files $uri $uri/ @handler; 
      expires 30d; 
     } 
     location ^~ /app/ { deny all; } 
     location ^~ /includes/ { deny all; } 
     location ^~ /lib/ { deny all; } 
     location ^~ /media/downloadable/ { deny all; } 
     location ^~ /pkginfo/ { deny all; } 
     location ^~ /report/config.xml { deny all; } 
     location ^~ /var/ { deny all; } 
     location /var/export/ { ## Allow admins only to view export folder 
      auth_basic "Restricted"; ## Message shown in login window 
      auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword 
      autoindex on; 
     } 
     location /. { ## Disable .htaccess and other hidden files 
      return 404; 
     } 
     location @handler { ## Magento uses a common front handler 
      rewrite//index.php; 
     } 
     location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler 
      rewrite ^(.*.php)/ $1 last; 
     } 
     location ~ .php$ { ## Execute PHP scripts 
      if (!-e $request_filename) { rewrite//index.php last; } 
      expires off; ## Do not cache dynamic content 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_param HTTPS $fastcgi_https; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      fastcgi_param MAGE_RUN_CODE default; 
      fastcgi_param MAGE_RUN_TYPE store; 
      include fastcgi_params; 
     }    
    } 

HTH

+0

嗯,這工作,但只有一點點。現在我得到'2013/08/20 15:04:42 [error] 591#0:* 6在內部重定向到「/favicon.ico」時重寫或內部重定向週期,客戶端:109.149.13.53,server:local .dyn.kwl.me,請求:「GET /favicon.ico HTTP/1.1」,主機:「local.dyn.kwl.me」,所以沒有所有索引的東西,只是favicon.ico錯誤。 –

+0

當我遇到同樣的問題時,我發現我在我的https根文件夾中鍵入了1個字符。檢查是否有錯別字。 – ShaunOReilly

0

試試這個

location/{ 
... 
try_files $uri $uri/ /index.php?q=$uri&$args; 
} 
+7

這將是一個好主意,給出一個簡要的解釋,爲什麼這會幫助提問者。 – RustyTheBoyRobot