Nginx代理,Apache上的WP。在wp-login.pphp

时间:2016-10-24 14:22:54

标签: wordpress apache nginx proxy

我使用nginx代理流量到Docker容器,但是我遇到了运行WordPress而不是Apache的容器问题。

博客工作正常,我看到帖子,图片......但我无法访问管理页面,因为重定向到wp-login.php返回302并且永远不会完成,所以在一些尝试浏览器之后抛出了太多重定向的错误。

代理配置:

server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;

    # HSTS
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;


    location /newWeb {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header   Host $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-Host $server_name;
        proxy_cookie_path / "/; secure; HttpOnly";
    }
    location /blog {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header   Host $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-Host $server_name;
        proxy_cookie_path / "/; secure; HttpOnly";
    }
}

server {
    listen 80;
    location /.well-known {
        alias /usr/local/etc/letsencrypt-webroot/.well-known;
    }
    return 301 https://$host$request_uri;
}

请注意,我没有寻找try_files指令来阻止循环,我试图找到成功重定向到 wp-login.php的解决方案

更新

这是来自Docker主机。 8080是我转发到Apache 80的端口。

wget http://127.0.0.1:8080/blog/wp-login.php
--2016-10-25 11:35:34--  http://127.0.0.1:8080/blog/wp-login.php
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://127.0.0.1:8080/blog/wp-login.php [following]
--2016-10-25 11:35:35--  https://127.0.0.1:8080/blog/wp-login.php
Connecting to 127.0.0.1:8080... connected.
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection.

我理解错误是因为Apache没有监听HTTPS,只是HTTP。这引出了两个问题:

  • 我怎么能用Nginx和Apache卸载SSL?从理论上讲,Apache并不需要预期HTTPS。
  • wget示例中,为什么要将其重定向到HTTPS?它不是通过nginx,而是直接通过Apache容器,VirtualHost就是这么简单:

    <VirtualHost *:80>
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    没有.htaccess

1 个答案:

答案 0 :(得分:1)

我在这个问题中找到了答案https://wordpress.stackexchange.com/questions/170165/wordpress-wp-admin-https-redirect-loop

我失踪了$_SERVER['HTTPS'] = 'on'。我不知道为什么它在wp-config.php中没有评论......