302使用nginx和WordPress重定向循环

前端之家收集整理的这篇文章主要介绍了302使用nginx和WordPress重定向循环前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我一直在Serverfault中搜索几个小时试图解决这个问题,但我找不到解决方案.会发生什么:

我在我的网站中使用wget进行了302重定向循环,但没有使用浏览器.在我的Nginx配置中,我只有两个301重定向,而不是302.我试图从wordpress禁用所有插件,没有运气.

可能导致问题的原因是什么?下面是我的Nginx配置. wget的一些例子:

wget elbauldelprogramador.com
    --2014-10-30 13:10:24--  http://elbauldelprogramador.com/
    Resolving elbauldelprogramador.com (elbauldelprogramador.com)... 
    Connecting to elbauldelprogramador.com (elbauldelprogramador.com)||:80... connected.
    HTTP request sent,awaiting response... 302 Moved Temporarily
    Location: 404 [following]
    --2014-10-30 13:10:25--  http://elbauldelprogramador.com/404
    Reusing existing connection to elbauldelprogramador.com:80.
    HTTP request sent,awaiting response... 302 Moved Temporarily
    Location: 404 [following]
    --2014-10-30 13:10:25--  http://elbauldelprogramador.com/404
    Reusing existing connection to elbauldelprogramador.com:80.
    [...]
    HTTP request sent,awaiting response... 302 Moved Temporarily
    Location: 404 [following]
    20 redirections exceeded.

以及服务器中的日志:

S.IP - - [30/Oct/2014:13:11:22 +0100] "GET /404 HTTP/1.1" 302 154 "-" "Wget/1.15 (linux-gnu)"
S.IP - - [30/Oct/2014:13:11:22 +0100] "GET /404 HTTP/1.1" 302 154 "-" "Wget/1.15 (linux-gnu)"
S.IP - - [30/Oct/2014:13:11:22 +0100] "GET /404 HTTP/1.1" 302 154 "-" "Wget/1.15 (linux-gnu)"

Nginx配置

server {
    #listen 127.0.0.1:81;
    listen 80;
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}

server {
#    listen 127.0.0.1:81;
    listen 80;
    server_name example.com 

    port_in_redirect off;
    server_tokens off;
    autoindex off;

    root /path;

    ## Page Speed Module ##
    include global/pagespeed.conf;

    ## Fastcgi cache start ##
    set $no_cache 0;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $no_cache 1;
    }
    if ($query_string != "") {
        set $no_cache 1;
    }

    # Don't cache uris containing the following segments
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.PHP|/wp-(app|cron|login|register|mail).PHP|wp-.*.PHP|/Feed/|index.PHP|wp-comments-popup.PHP|wp-links-opml.PHP|wp-locations.PHP|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $no_cache 1;
    }

    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
        set $no_cache 1;
    }

    # Deliver 404 instead of 403 "Forbidden"
    error_page 403 = 404;

    include global/restrictions.conf;
    include global/caching.conf;


    # Additional rules go here.
    access_log log/access.log;
    error_log log/error.log warn;

    rewrite ^/sitemap_index\.xml$/index.PHP?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$/index.PHP?sitemap=$1&sitemap_n=$2 last;

    location = /p/guia-de-desarrollo-android.html {
        rewrite  /p/guia-de-desarrollo-android.html http://example.com/curso-programacion-android/ permanent;
    }

    location = /p/bases-de-datos.html {
        rewrite  /p/bases-de-datos.html http://example.com/bases-de-datos/ permanent;
    }

    location = /Feeds/posts/default {
        rewrite /Feeds/posts/default http://example.com/Feed permanent;
    }

    location = /p/guias-gratuitas.html {
        rewrite /p/guias-gratuitas.html http://example.com/manuales-gratuitos/ permanent;
    }

    # Only include one of the files below.
    include global/wordpress.conf;
    include global/security.conf;

}

include global / wordpress.conf;

#wordpress single blog rules.
# Designed to be included in any server {} block.

#A little something from the Search Overload blog entry
location = /search { 
    limit_req zone=wpsearch burst=3 nodelay;
    try_files $uri /index.PHP; 
}

location / {
    try_files $uri $uri/ /index.PHP;
}

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|RSS|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)${
    access_log off; log_not_found off; expires max;
}

# Pass all .PHP files onto a PHP-fpm/PHP-fcgi server.
location ~ \.PHP${

    # Zero-day exploit defense.
    # http://forum.Nginx.org/read.PHP?2,88845,page=3
    # Won't work properly (404 error) if the file is not stored on this server,which is entirely possible with PHP-fpm/PHP-fcgi.
    # Comment the 'try_files' line out if you set up PHP-fpm/PHP-fcgi on another machine.  And then cross your fingers that you won't get hacked.
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
    #NOTE: You should have "cgi.fix_pathinfo = 0;" in PHP.ini

    include fastcgi_params;
    fastcgi_index index.PHP;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass PHP;

    ##
    # Fastcgi cache
    ##
    fastcgi_cache_bypass $no_cache;
    fastcgi_no_cache $no_cache;
    fastcgi_cache microcache;
    fastcgi_cache_valid 60m;
}

提前致谢.

最佳答案
您的Nginx配置有误:

    error_page 403 = 404;

这会导致Nginx尝试重定向到名为“404”的文档,这正是发生的事情.

这应该写成:

    error_page 403 =404;

或者更好的是,它根本不存在.发送一个明显错误错误代码是混淆人们(像你自己)的好方法.

原文链接:https://www.f2er.com/nginx/435301.html

猜你在找的Nginx相关文章