nginx Wordpress Static使用HTTP而不是HTTPS

z4iuyo4d  于 2024-01-06  发布在  Nginx
关注(0)|答案(2)|浏览(291)

我在Docker容器中有一个WordPress服务器。WordPress在里面运行Nginx服务器。当我经历初始安装阶段时,CSS(和其他文件)工作得很好。但是当我加载主站点时,这些资源重定向到HTTP://example.com/blogs/.而不是HTTPS。
以下是来自inspect的URL:

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

字符串
以下是我从example.com获得的Nginx配置:

  1. location /blogs/ {
  2. proxy_pass HTTP://localhost:8080/;
  3. proxy_set_header Host $host;
  4. proxy_set_header X-Real-IP $remote_addr;
  5. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  6. proxy_read_timeout 1800s;
  7. }


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

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


请让我知道如果你需要更多的信息。

  • 更新#1 -
    Nginx服务器块
  1. server {
  2. root /var/www/html;
  3. index index.php index.html index.htm;
  4. server_name example.com; # managed by Certbot
  5. location /blogs/ {
  6. proxy_pass HTTP://localhost:8080/;
  7. proxy_set_header Host $host;
  8. proxy_set_header X-Real-IP $remote_addr;
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  10. proxy_read_timeout 1800s;
  11. }
  12. listen [::]:443 ssl ipv6only=on; # managed by Certbot
  13. listen 443 ssl; # managed by Certbot
  14. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  15. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  16. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  17. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # :managed by Certbot
  18. if ($scheme != https) {
  19. return 301 https://$host$request_uri;
  20. }
  21. }
  22. server {
  23. if ($host = example.com) {
  24. return 301 https://$host$request_uri;
  25. } # managed by Certbot
  26. listen 80 ;
  27. listen [::]:80 ;
  28. server_name example.com;
  29. return 404; # managed by Certbot
  30. }

xdnvmnnf

xdnvmnnf1#

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

omqzjyyz

omqzjyyz2#

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

  1. server {
  2. listen 80;
  3. listen 443 ssl http2;
  4. server_name example.com www.example.com;
  5. the rest of your code
  6. if ($scheme != https) {
  7. return 301 https://example.com$request_uri;
  8. the rest of your code
  9. }

字符串

相关问题