沃梦达 / 编程技术 / CMS教程 / 正文

wordpress – Nginx’重写或内部重定向循环,同时内部重定向’导致500

我对Raspbian喘息的nginx 1.2.1-2.2有点问题.我认为它是在我更改了我的sites-available / default文件中的索引之后开始的.以下是相关文件:nginx.confuser www-data;worker_processes 4;pid /var/run/nginx.pid;e...

我对Raspbian喘息的nginx 1.2.1-2.2有点问题.我认为它是在我更改了我的sites-available / default文件中的索引之后开始的.以下是相关文件:

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"

我想象我的sites-default文件中的index或try_files有问题.谁能看到什么?

解决方法:

我经常在Nginx上运行WordPress网站.如果您可以使用它们,那么这是位置指令的部分成功配置. Nginx版本是1.0.15.您可能希望更改fastcgi_pass参数以运行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;
    }

本文标题为:wordpress – Nginx’重写或内部重定向循环,同时内部重定向’导致500

基础教程推荐