nginx ssl 反向代理wordpress

wordpress部署在docker上,使用http协议,现在部署https协议,增设一个nginx服务器,反向代理http协议的wordpress

nginx反向代理需要增设协议头

1
proxy_set_header X-Forwarded-Proto $scheme; 

完整的nginx反向代理设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
server_nameopenwares.net;
listen8443 ssl http2;

ssl_certificate /etc/nginx/ssl/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/openwares.net.key;
ssl_protocols TLSv1.3;

location / {
proxy_pass http://localhost/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Accept-Encoding "gzip";
}
}

编辑wordpress的wp-config.php文件,在文件前面添加

1
2
3
define('FORCE_SSL_ADMIN', true);
if ($_SERVER\['HTTP_X_FORWARDED_PROTO'\] == 'https')
$_SERVER\['HTTPS'\]='on';

最后需要参考[3]将数据库中的链接从http修改为https。

References:
[1]Administration Over SSL
[2]WordPress使用Nginx做反向代理的SSL设置
[3]MySQL Queries To Change WordPress From HTTP to HTTPS In The Database