当访问代理中使用apache和nginx托管的wordpress时,重定向至127.0.0.1诊断树


Redirect to 127.0.0.1 when access a wordpress hosted with apache and nginx in proxy

我在Apache2上托管了一个wordpress,前面有Nginx。 <WORLD> ===> <NGINX PROXY> --> APACHE/DOCKER/STATIC WEBSITE etc...

我的wordpress代理的nginx conf是:

server {
    server_name dev-www.example.com;
    location / {
        proxy_pass http://127.0.0.1:13400;
    }
}

我的apache配置:

Listen 13400
<VirtualHost 127.0.0.1:13400>
        CustomLog /var/log/httpd/sites/dev-www/access_log combined
        ErrorLog /var/log/httpd/sites/dev-www/error_log
        DirectoryIndex index.php
        DocumentRoot /var/www/sites/example.com/dev-www
        RewriteEngine On
        <Directory /var/www/sites/example.com/dev-www/>
                Options Indexes FollowSymLinks
                AllowOverride all
        </Directory>
</VirtualHost>

和wordpress .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress

问题是当我进入dev-www.example.com/foobar.php时,我会被重定向到127.0.0.1/foobar.php。我知道它是从nginx配置127.0.0.1弹出的,怎么修复它?

我试图代理传递到dev-www.example.com:13400,但我得到了一个无限循环:

【2016年5月10日星期二23:44:45.001680】【核心:错误】【pid 1096】【客户端127.0.0.1:54887]AH00124:由于可能的配置错误,请求超过了10个内部重定向的限制。使用"LimitInternalRecursion"以在必要时增加限制。使用"LogLevel debug"以获取回溯。,引用人:http://dev-www.example.com/

注意:http://dev-www.example.comhttp://dev-www.example.com/index.php没有问题谢谢

注2:如果我将nginx配置更改为localhost:13400,那么我将被重定向到localhost/login-3。它看起来像.htaccess重定向到ServName,它是127.0.0.1

这是wordpress重定向到HTTP_HOST,添加

$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];

wp-config.php中修复它。

听起来就像您已经将wordpress站点从本地开发系统导出到生产系统。很可能你再也无法进入/wp管理了。在这种情况下,您必须手动更新表wp_options中的数据库条目。查找选项siteurlhome


也请尝试将其添加到wp-config.php中(但恐怕,这只针对传出的请求)

define('WP_PROXY_HOST', '1.2.3.4');
define('WP_PROXY_PORT', '13400');
# define('WP_PROXY_USERNAME', 'my_user_name');
# define('WP_PROXY_PASSWORD', 'my_password');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');

对于Nginx,您必须确保主机标头设置正确,您的示例应该是:

server {
    server_name dev-www.example.com;
    location / {
        proxy_set_header Host dev-www.example.com;
        proxy_pass http://127.0.0.1:13400;
    }
}