且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 SSL 的 nginx 反向代理背后的 Docker 上的 Wordpress

更新时间:2021-09-04 01:58:29

实际上我找到了解决方案!我的 nginx 配置有错误,如果有人感兴趣,这是我的最终工作配置:

Actually I found my way through it ! I had an error in my nginx configuration and if anyone is interested, here is my final working configuration :

nginx.conf 文件(wordpress 块):

nginx.conf file (wordpress bloc) :

location /blog/ {
        proxy_pass http://127.0.0.1:8093/;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_read_timeout    90;
        proxy_connect_timeout 90;
        proxy_redirect        off;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Port 443;
        proxy_set_header Proxy "";
    }

这是我在 wordpress 容器的 wp_config.php 文件顶部添加的内容:

Here is what I added at the top of wp_config.php file of my wordpress container :

define('FORCE_SSL_ADMIN', true);

$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){

    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

define('WP_HOME','https://test.com/blog/');
define('WP_SITEURL','https://test.com/blog/');

干杯!