为什么wordpress示例已停止正常工作后,安装让使用nginx加密ssl?

rbpvctlc  于 2022-11-02  发布在  Nginx
关注(0)|答案(2)|浏览(212)

安装后让我们通过certbot加密我的WordPress网站已停止加载css/js正确。它总是返回Blocked loading mixed active content。如果我改变http://example.comhttps://example.com在WP管理面板网站服务器返回too many redirections错误。
以下是一些详细信息。
我的Nginx配置

server {
    server_name example.com www.example.com

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8000;
        include /etc/nginx/mime.types;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/vergisistemi.az/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/vergisistemi.az/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
    # return 404; # managed by Certbot

}

以下是docker ps返回的内容:

CONTAINER ID   IMAGE                PORTS                                   NAMES
571d2d2c7e12   wordpress:latest     0.0.0.0:8000->80/tcp, :::8000->80/tcp   wordpress
265b6e159bc2   mysql:5.7            3306/tcp, 33060/tcp                     mysql
4bbkushb

4bbkushb1#

在寻找解决方案的半天之后,我发现需要做一些小的改变:
第一步,将define('FORCE_SSL_ADMIN', true);添加到wp-config.php文件中;
第二步-在nginx配置文件中添加proxy_set_header X-Forwarded-Proto $scheme;location

location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8000;
        include /etc/nginx/mime.types;
    }

瞧!一切都很顺利!

uurv41yg

uurv41yg2#

将以下代码添加到wp-config.php的顶部对我来说很有用:

define('FORCE_SSL_ADMIN', true);

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';

相关问题