之前部署了一个 Discourse 站点 部署在一台配置比较高但是线路没有优化的机器上
容器内部使用 nginx 然后通过 Unix Socket 使用宿主机的 Caddy 进行域名访问
之后我在线路比较好的香港服务器上部署 Nginx 对原站进行反代
但是反代后为502
,无法正常访问 我看了下error.log
说的是代理服务器和源站 ssl 握手失败 但是我在代理服务器里面写的是https
,而且代理服务器curl
能正常获取到内容
这个是源站的caddyfile
direct.example.com {
reverse_proxy unix//var/discourse/shared/standalone/nginx.http.sock {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
}
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}
synapse.know-cnu.wiki {
reverse_proxy localhost:8008 {
# WebSocket 连接的默认配置
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
# 处理 WebSocket 连接
transport http {
read_buffer 0
}
}
# 设置 HSTS 头部
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
这个是代理服务器的nginx.conf
,未使用ssl
server {
listen 80;
server_name example.com;
location / {
proxy_pass https://direct.example.com;
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;
}
}
error.log
如下
root@VM80459:~# tail -f /var/log/nginx/error.log
2024/08/24 06:08:57 [emerg] 3325#3325: "server" directive is not allowed here in /etc/nginx/nginx.conf:11
2024/08/24 06:09:05 [emerg] 3326#3326: "server" directive is not allowed here in /etc/nginx/nginx.conf:11
2024/08/24 06:10:18 [notice] 3373#3373: signal process started
2024/08/24 06:19:53 [notice] 3445#3445: signal process started
2024/08/24 06:20:02 [error] 3446#3446: *12 SSL_do_handshake() failed (SSL: error:0A000438:SSL routines::tlsv1 alert internal error:SSL alert number 80) while SSL handshaking to upstream, client: 1xx.1x.5x.xx, server: know-cnu.wiki, request: "GET / HTTP/1.1", upstream: "https://[2400:61xx:0:dx::xa:a0x]:443/", host: "example.com"
2024/08/24 06:20:02 [error] 3446#3446: *12 SSL_do_handshake() failed (SSL: error:0A000438:SSL routines::tlsv1 alert internal error:SSL alert number 80) while SSL handshaking to upstream, client: 10x.13x.5x.18x, server: example.com, request: "GET / HTTP/1.1", upstream: "https://15x.8x.2xx.xx:443/", host: "example.com"
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.