【发布时间】:2021-02-28 01:00:31
【问题描述】:
我让 nginx 在运行 Wordpress 的网络服务器前充当反向代理。 我不确定我的问题是 nginx、php 还是 WordPress,所以我正在寻求帮助。
我有一个在 Docker 中运行的 nginx 服务器,它充当反向代理。 在这台服务器后面有一个网络服务器,同样在 Docker 中运行,运行 WordPress。
在 http 上运行时一切正常。但是我要转到 https 并且无法正常工作。
我收到“混合模式”消息,说样式表和脚本被阻止,因为它们是通过 https 提供的。
在 WordPress 中,我添加了以下内容,如 here 到 wp-config.php:
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
我也改变了这个:
define('WP_HOME', 'https://www.example.com');
define('WP_SITEURL', 'https://www.example.com');
我还将数据库中引用http://www.example.com 的所有内容都更改为https://www.example.com
当我输入 https://www.example.com 时,我收到 1 条关于通过 http 加载样式表的“混合内容”警告,即使有一个样式表加载得很好。
如果我输入https://www.example.com/wp-admin,我会得到很多样式表和脚本的混合内容。
所有这些链接都可以通过 https 访问,但不知何故,它们仍然通过 http 提供服务。 我搜索了数据库中的每个文件和所有内容,但在任何地方都找不到对 http://example.com 的任何引用。
这是反向代理:
server {
listen 80;
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com example.com;
ssl_certificate /etc/ssl/private/example.com/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com/example.com.key;
location / {
proxy_pass http://10.0.100.10:8082;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
这是后端
server {
server_name _;
listen 80;
root /var/www/myapp;
index index.php index.html index.htm;
access_log /var/log/nginx/back-access.log;
error_log /var/log/nginx/back-error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# PHP-FPM Configuration Nginx
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-domain:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
谁能理解为什么会发生这种情况以及问题出在哪里?
【问题讨论】:
标签: wordpress nginx nginx-reverse-proxy