【问题标题】:WordPress infinite redirect loop when accessing wp-admin访问 wp-admin 时的 WordPress 无限重定向循环
【发布时间】:2015-11-29 00:05:56
【问题描述】:

我刚刚将我的 wordpress 博客移到了新服务器上。我重新配置了 nginx conf 文件,前端工作得很好。 但是,当我尝试访问 mywebsite.com/wp-admin 区域时,我会得到一个无限重定向循环,但是如果我添加 index.php (mywebsite.com/wp-admin/index.php) 它可以工作。我正在拉扯我的头发,因为我不明白为什么 nginx 会这样

我已经在论坛上看到过这样的问题,但在我的情况下,conf 文件似乎是正确的(与我的旧服务器上的相同)

我还禁用了所有插件(以防万一),我得到了相同的行为

在这里你可以找到我的 nginx 配置文件

server {
    listen 80;
    server_name mywebsite.com www.mywebsite.com;
    root /home/mywebsite;
    index /index.php;
    access_log /var/log/nginx/www.mywebsite.com.access.log;
    error_log /var/log/nginx/www.mywebsite.com.error.log;
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\. {
    deny all;
    } 

    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
    } 

    # WordPress single site rules.
    # Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
    try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri permanent;

# Add trailing slash to */wp-admin requests.
#rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# 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;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

#ss all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
    #fastcgi_index /index.php;
    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/mywebsite/dynamic$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
#   fastcgi_intercept_errors on;
}

谢谢你的帮助

【问题讨论】:

    标签: php wordpress redirect nginx infinite


    【解决方案1】:

    服务器上已经安装了其他 wordpress 实例。您需要将 ISPConfig 中的 nginx 指令重写为:

    location / {
                    try_files $uri $uri/ /index.php?$args;
    
                   # Add trailing slash to */wp-admin requests.
                   rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
                   location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                        expires max;
                        log_not_found off;
                   }
                   # Deny public access to wp-config.php
                   location ~* wp-config.php { 
                        deny all; 
                   }
    
    }
    

    在子文件夹中也包含相同的内容。通常它的 ISPConfig 路径是 /home/admispconfig/ispconfig/lib/config.inc.php 或者你可以在你的服务器上搜索

    【讨论】:

    • 嗨,谢谢您的宝贵时间,不,我的服务器上没有其他 wordpress 实例。我尝试在 $host$uri 之后添加“/”,但我仍然面临同样的问题:(有什么想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 2019-04-16
    • 2013-01-10
    相关资源
    最近更新 更多