Nginx 反向代理 CLoudflare 的 Pages 项目域名出错 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
StephenJoseDai
V2EX    Cloudflare

Nginx 反向代理 CLoudflare 的 Pages 项目域名出错

  •  
  •   StephenJoseDai 131 天前 1266 次点击
    这是一个创建于 131 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在 Cloudflare 的 Pages 上部署了 github 的项目,默认域名是.dev 的,于是我绑定了一个在 cloudflare 上托管的域名,假设是 abc.com ,项目解析的是 pj.abc.com ,我访问 pj.abc.com 的时候是 reset ,因为长城的原因,我只能使用 VPN ,但这不是一个好办法,于是我找到了一台能够翻墙的 Linux 服务器,使用 nginx 对这个域名进行反向代理,但是似乎访问时会报 502 ,这个是啥问题引起的?

    server { listen 6659; server_name pj.123.com; access_log /var/nginx/logs/http_proxy_access.log main; error_log /var/nginx/logs/http_proxy_error.log debug; if ($host ~* "^pj.123.com$") { rewrite ^/(.*)$ https://pj.123.com:7956$request_uri permanent; } } server { listen 7956 ssl; server_name pj.123.com; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; access_log /var/nginx/logs/https_proxy_access.log main; error_log /data/nginx/logs/https_proxy_error.log debug; gzip on; gzip_comp_level 9; gzip_types text/css text/plain text/xml application/Javascript application/x-Javascript application/html application/xml image/png image/jpg image/jpeg image/gif image/webp image/svg+xml; charset utf-8; ssl_certificate /etc/sssl_cert/pj.123.com.crt; ssl_certificate_key /etc/ssl_cert/pj.123.com.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; location / { proxy_pass https://pj.abc.com; proxy_connect_timeout 30; proxy_read_timeout 60; proxy_send_timeout 60; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header Connection "upgrade"; #proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Forwarded-Proto $scheme; proxy_ssl_server_name on; } } 

    我看了下日志,似乎是报 SSL 的问题

    2025/08/08 03:46:46 [error] 22#22: *7 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 3.5.2.4, server: pj.123.com, request: "GET / HTTP/1.1", upstream: "https://104.21.89.160:443/", host: "pj.123.com:7956" 2025/08/08 03:46:46 [warn] 22#22: *7 upstream server temporarily disabled while SSL handshaking to upstream, client: 3.5.2.4, server: pj.123.com, request: "GET / HTTP/1.1", upstream: "https://104.21.89.160:443/", host: "pj.123.com:7956" 2025/08/08 03:46:46 [error] 22#22: *7 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 3.5.2.4, server: pj.123.com, request: "GET / HTTP/1.1", upstream: "https://172.67.189.154:443/", host: "pj.123.com:7956" 2025/08/08 03:46:46 [warn] 22#22: *7 upstream server temporarily disabled while SSL handshaking to upstream, client: 3.5.2.4, server: pj.123.com, request: "GET / HTTP/1.1", upstream: "https://172.67.189.154:443/", host: "pj.123.com:7956" 2025/08/08 03:46:46 [error] 22#22: *7 no live upstreams while connecting to upstream, client: 3.5.2.4, server: pj.123.com, request: "GET /favicon.ico HTTP/1.1", upstream: "https://pj.abc.com/favicon.ico", host: "pj.123.com:7956", referrer: "https://pj.123.com:7956/" 
    9 条回复    2025-08-08 19:59:56 +08:00
    ChicC
        1
    ChicC  
       131 天前
    proxy_set_header Host pj.abc.com;
    StephenJoseDai
        2
    StephenJoseDai  
    OP
       131 天前
    @ChicC 后面我也加了,也还是 502
    StephenJoseDai
        3
    StephenJoseDai  
    OP
       131 天前
    @ChicC location 部分现在是这样

    location / {
    proxy_pass https://pj.abc.com;
    proxy_set_header Host pj.abc.com;
    proxy_ssl_server_name on;
    }
    ankikong
        4
    ankikong  
       131 天前
    proxy pass 放到最下面
    ankikong
        5
    ankikong  
       131 天前
    上面再加个 proxy_ssl_name pm.abc.com
    ChicC
        6
    ChicC  
       130 天前
    proxy_pass https://pj.abc.com;
    proxy_set_header Host pj.abc.com;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_ssl_server_name on;
    ChicC
        7
    ChicC  
       130 天前 via iPhone
    或者你反代默认的那个 dev 域名
    StephenJoseDai
        8
    StephenJoseDai  
    OP
       130 天前
    试了你俩的,好像还是 502 ,反向代理 dev 那个也一样

    2025/08/08 19:51:03 [error] 22#22: *1 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 3.2.5.1, server: y.daish.eu.org, request: "GET / HTTP/1.1", upstream: "https://172.67.189.154:443/", host: "pj.123.com:7956"
    2025/08/08 19:51:03 [warn] 22#22: *1 upstream server temporarily disabled while SSL handshaking to upstream, client: 3.2.5.1, server: y.daish.eu.org, request: "GET / HTTP/1.1", upstream: "https://172.67.189.154:443/", host: "pj.123.com:7956"
    2025/08/08 19:51:03 [error] 22#22: *1 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking to upstream, client: 3.2.5.1, server: y.daish.eu.org, request: "GET / HTTP/1.1", upstream: "https://104.21.89.160:443/", host: "pj.123.com:7956"
    2025/08/08 19:51:03 [warn] 22#22: *1 upstream server temporarily disabled while SSL handshaking to upstream, client: 3.2.5.1, server: y.daish.eu.org, request: "GET / HTTP/1.1", upstream: "https://104.21.89.160:443/", host: "pj.123.com:7956"
    2025/08/08 19:51:03 [error] 22#22: *1 no live upstreams while connecting to upstream, client: 3.2.5.1, server: y.daish.eu.org, request: "GET /favicon.ico HTTP/1.1", upstream: "https://pj.abc.com/favicon.ico", host: "pj.123.com:7956", referrer: "https://pj.123.com:7956/"


    server {
    listen 7956 ssl;
    server_name pj.123.com;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    access_log /data/nginx/logs/https_pj_access.log main;
    error_log /data/nginx/logs/https_pj_error.log debug;
    #gzip on;
    #gzip_comp_level 9;
    #gzip_types text/css text/plain text/xml application/Javascript application/x-Javascript application/html application/xml image/png image/jpg image/jpeg image/gif image/webp image/svg+xml;
    charset utf-8;
    ssl_certificate /data/ssl_cert/pj.123.com.crt;
    ssl_certificate_key /data/ssl_cert/pj.123.com.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    location / {
    proxy_set_header Host pj.abc.com;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_ssl_server_name on;
    proxy_ssl_name pj.abc.com;
    proxy_pass https://pj.abc.com;
    }
    }
    StephenJoseDai
        9
    StephenJoseDai  
    OP
       130 天前
    哦,好像是缓存,为啥反向代理 dev 就可以,反代自己的域名就不行啊?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3729 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 10:21 PVG 18:21 LAX 02:21 JFK 05:21
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86