NGINX 反向代理混合內容可能是設定錯誤

NGINX 反向代理混合內容可能是設定錯誤

我在用著伺服器A(NGINX 作為 WordPress 的網頁伺服器)和伺服器B(NGINX 作為反向代理)並從 Let's Encrypt with Certbot 取得 SSL 憑證後伺服器B我正在接收

Mixed Content: The page at 'https://example.net/' was loaded over 
 HTTPS, but requested an insecure script 
'http://xx.xx.xx.xx/wp-includes/js/wp-emoji-release.min.js?ver=5.8'. 
This request has been blocked; the content must be served over HTTPS.

且頁面載入時沒有任何 JPG 或 CSS。
伺服器A配置

server {
            listen 80;
            root /var/www/wordpress;
            index index.php index.html;

            access_log /var/log/nginx/example.access.log;
            error_log /var/log/nginx/example.error.log;

            location / {
                        try_files $uri $uri/ =404;
            }

            location ~ \.php$ {
                         include snippets/fastcgi-php.conf;
                         fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            }

            location ~ /\.ht {
                         deny all;
            }

            location = /favicon.ico {
                         log_not_found off;
                         access_log off;
            }

            location = /robots.txt {
                         allow all;
                         log_not_found off;
                         access_log off;
           }

            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                         expires max;
                         log_not_found off;
           }

            location /wp-admin/ {
                index index.php
            try_files $uri $uri /index.php?$args;
    }
}

伺服器B配置

server {
    if ($host = example.net) {
        return 301 https://example.net$request_uri;
    }

    if ($host = www.example.net) {
        return 301 https://example.net$request_uri;
    }

   server_name example.net www.example.net;
    listen 80;
    return 404;

}
server {
        listen 0.0.0.0:443 ssl http2;

        server_name example.net www.example.net;

         ssl_certificate      /etc/letsencrypt/live/example.net/fullchain.pem;
         ssl_certificate_key  /etc/letsencrypt/live/example.net/privkey.pem;

        location ~ /.well-known/acme-challenge {
                allow all;
        }

    location / {

    proxy_pass            http://xx.xx.xx.xx/;
    proxy_read_timeout    90;
    proxy_connect_timeout 90;
    proxy_redirect        off;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_ssl_server_name on;

    }
}

伺服器A託管 WordPress。有人可以幫助我,因為我的配置文件可能搞砸了......提前致謝。

解決方案:在 Nginx cfg 中新增:

add_header 'Content-Security-Policy' 'upgrade-insecure-requests';

WordPress 位址 (URL) 和網站位址 (URL) 也發生了變化。

相關內容