【问题标题】:Reverse proxy from Nginx to Dockerized Wordpress is causing an infinite redirect loop从 Nginx 到 Dockerized Wordpress 的反向代理导致无限重定向循环
【发布时间】:2019-04-08 03:22:52
【问题描述】:

我的 Wordpress 网站应该出现在 http://192.168.122.50/blog/

我从创建这个服务器块开始

server {
  server_name 192.168.122.50;
  listen 80;

  location /blog/ {
    proxy_pass http://localhost:8000; # My Wordpress site
  }
}

接下来,我将以下两行添加到我的 Wordpress 配置 (wp-config.php):

define( 'WP_HOME', 'http://192.168.122.50/blog/' );                                                                                  
define( 'WP_SITEURL', 'http://192.168.122.50/blog/' );   

我不断收到指向此 URL 的无限重定向循环:http://192.168.122.50/blog/wp-admin/install.php

这是我收到的 HTTP 响应,根据 httpie:

HTTP/1.1 302 Found
Cache-Control: no-cache, must-revalidate, max-age=0
Connection: keep-alive
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Sun, 07 Apr 2019 15:13:50 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Location: http://192.168.122.50/blog/wp-admin/install.php
Server: nginx/1.12.2
X-Powered-By: PHP/7.2.17
X-Redirect-By: WordPress

我试图通过在 proxy_pass 之后添加以下行来解决此问题,但无济于事。

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

另外,我正在使用wordpress:latest Docker 映像。

【问题讨论】:

    标签: wordpress docker nginx reverse-proxy


    【解决方案1】:

    Wordpress 在内部使用 apache Web 服务器来路由请求,所以我假设您将 nginx 放在 wp-apache 堆栈之上。

    您应该能够通过简单地使用下面的块将每个到达 nginx 代理的请求传递给 apache 来做到这一点

    server {
      server_name _;
      listen 80;
        location / {
           proxy_pass http://localhost:8000;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-28
      • 2020-09-22
      • 1970-01-01
      • 2019-08-31
      • 2016-01-09
      • 2011-06-04
      • 1970-01-01
      • 2021-10-21
      • 2020-06-06
      相关资源
      最近更新 更多