【问题标题】:Wordpress Static going to HTTP instead of HTTPSWordpress Static 使用 HTTP 而不是 HTTPS
【发布时间】:2021-07-14 08:32:53
【问题描述】:

我在 docker 容器内有一个 WordPress 服务器。 WordPress 在内部运行 nginx 服务器。当我完成初始安装阶段时,css(和其他文件)运行良好。但是当我加载主站点时,这些资源被重定向到 HTTP://example.com/blogs/... 而不是 HTTPS。

以下是检查中的 URL:

https://example.com/blogs/
http://example.com/blogs/wp-includes/js/wp-emoji-release.min.js?ver=5.1.1

这是来自 example.com 的我的 Nginx 配置:

location /blogs/ {
                proxy_pass HTTP://localhost: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_read_timeout 1800s;
        }

我已经用以下信息更新了 wp-config.php 文件

define('WP_HOME','https://example.com/blogs/');
define('WP_SITEURL','https://example.com/blogs/');
$_SERVER['REQUEST_URI'] = '/blogs' . $_SERVER['REQUEST_URI'];

如果您需要更多信息,请告诉我。

--- 更新 #1 ---

Nginx 服务器块

server {
        root /var/www/html;
        index index.php index.html index.htm;

        server_name example.com; # managed by Certbot
       
        location /blogs/ {
                proxy_pass HTTP://localhost: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_read_timeout 1800s;
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/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
    if ($scheme != https) {
          return 301 https://$host$request_uri;
    }
}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name example.com;
    return 404; # managed by Certbot
}

【问题讨论】:

  • 你的服务器阻塞在 nginx 中是什么样子的?
  • 我在问题描述上有 nginx 块。

标签: php wordpress docker nginx docker-compose


【解决方案1】:

如果 siteurlhome 也使用 https 设置,请检查 wp_options 表。

【讨论】:

    【解决方案2】:

    假设您的域有一个服务器块,请确保您的服务器块中有这些行,以将所有非 https 请求重定向到 https:

        server {
            listen 80;
            listen 443 ssl http2;
            server_name example.com www.example.com;
    the rest of your code
            if ($scheme != https) {
                return 301 https://example.com$request_uri;
    the rest of your code
        }
    

    【讨论】:

    • 我已经在我的问题描述中更新了 nginx 服务器块。但是问题仍然存在。
    • 尝试用if ($scheme != https) { return 301 https://example.com$request_uri;替换server { if ($host = example.com) { return 301 https://$host$request_uri; }并简单重启nginx,systemctl restart nginx
    • 更改后问题仍然存在。
    猜你喜欢
    • 2016-01-29
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 2018-08-17
    • 2011-05-03
    相关资源
    最近更新 更多