我有一个 Docker 服务跑着 Wordpress ,域名假设是 wp.name.com ,使用 HTTP ,无 HTTPS 。为了使用 SSL ,再另一个 docker 容器里跑了个 nginx ,监听 443 端口然后反向代理了
server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/nginx/certs/yourdomain.com.crt;
ssl_certificate_key /etc/nginx/certs/yourdomain.com.key;
location / {
proxy_pass http://<wordpress-ip>:80;
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_set_header X-Forwarded-Proto $scheme;
}
}
用https://wp.name.com
打开网页是没问题了,但是 Wordpress 使用的静态文件还是在 HTTP 上,因此加载失败。请问这种情况有什么好办法么?谢谢
1
julyclyde 2023-03-08 13:22:18 +08:00
我记得 wordpress 里给出的静态资源好像都是绝对路径
所以需要改一遍数据库 |
2
Kinnice 2023-03-08 13:22:51 +08:00
`UPDATE wp_posts SET post_content = replace( post_content, 'http 域名','https 域名');`
|
3
leaflxh 2023-03-08 13:28:39 +08:00
改一下 80 升级 443 的逻辑?
server { listen 80; server_name www.域名.com; rewrite ^(.*)$ https://${server_name}$1 permanent; } 查询自 https://blog.csdn.net/zhuchunyan_aijia/article/details/121374258 |
4
lanternxx 2023-03-08 13:31:47 +08:00
先在 wordpress 管理后台的设置里把站点地址和站点 URL 改成 https 的试试,不行的话就要按楼上的刷数据库了
|
5
leaflxh 2023-03-08 14:42:05 +08:00
以下配置未复现:
docker-compose.yaml: version: '3.1' services: wordpress: image: wordpress restart: always ports: - 8080:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: exampleuser WORDPRESS_DB_PASSWORD: examplepass WORDPRESS_DB_NAME: exampledb volumes: - wordpress:/var/www/html db: image: mysql:5.7 restart: always environment: MYSQL_DATABASE: exampledb MYSQL_USER: exampleuser MYSQL_PASSWORD: examplepass MYSQL_RANDOM_ROOT_PASSWORD: '1' volumes: - db:/var/lib/mysql volumes: wordpress: db: nginx 配置: server { listen 80; server_name example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example.com; ssl_certificate /etc/nginx/cert/example.com/cert.crt; ssl_certificate_key /etc/nginx/cert/example.com/cert.key; client_max_body_size 1G; client_body_buffer_size 16M; location / { proxy_pass http://127.0.0.1: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_set_header X-Forwarded-Proto $scheme; } } |
6
xuanbg 2023-03-08 14:53:02 +08:00
简单反代一下不行吗?当然如果图片 url 是绝对路径的话,那肯定要在数据库里面把 http 替换成 https 才行。
|
7
r00t7 2023-03-08 15:03:18 +08:00
|
9
r00t7 2023-03-08 17:38:19 +08:00
@dangyuluo 主要是最后的内容
/**请求标头告知**/ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $_SERVER['HTTPS'] = 'on'; } |
10
kingfalse 2023-03-08 22:46:54 +08:00 via Android
lnmp 一把梭子搞定
|