honmaple
V2EX  ›  问与答

nginx 无证书的情况下能否转发 https 流量到另一个 nginx

  •  
  •   honmaple · Oct 31, 2024 · 1683 views
    This topic created in 567 days ago, the information mentioned may be changed or developed.

    现在主机上的 80 和 443 端口被占用,所以我部署的一个Nginx Proxy Manager只能使用 8080 和 8443 ,现在想要把指定域名的流量转到 8080 和 8443

    我添加的 nginx 配置

    server {
    	listen 80;
    	listen [::]:80;
    
    	server_name nas.example.com *.nas.example.com;
    
            location / {
                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_pass http://127.0.0.1:8080;
            }
    }
    
    server {
            listen 443 ssl;
            listen [::]:443 ssl;
    
    	server_name nas.example.com *.nas.example.com;
    
            location / {
                proxy_pass https://127.0.0.1:8443;
                proxy_ssl_name $host;
                proxy_ssl_server_name on;
            }
    }
    

    现在 80 端口转发是正常的,但 443 端口总是返回 502 ,报错信息

    2024/10/31 22:17:43 [error] 3401182#3401182: *120377 upstream prematurely closed connection while reading response header from upstream, client: 192.168.31.8, server: nas.exmaple.com, request: "GET / HTTP/1.1", upstream: "https://127.0.0.1:8443/", host: "dns.nas.exmaple.com"
    

    我知道 stream+ssl_preread 应该可以实现这个功能,但侵入性太大,想问一下有没有其它的方式

    4 replies    2024-11-01 10:07:57 +08:00
    leyoumake1997
        1
    leyoumake1997  
       Oct 31, 2024
    Actrace
        2
    Actrace  
       Nov 1, 2024
    nginx 可以设置 upstream 不验证 SSL ,这样你就可以使用自签证书来做对接。
    不过,既然你用了 UI ,那么难免会受限于 UI 能做到的事情,直接编写配置文件会比较好。
    CodeCodeStudy
        3
    CodeCodeStudy  
       Nov 1, 2024
    在 443 端口那里
    proxy_pass http://127.0.0.1:8080;
    这样不就行了吗
    kur0d3s
        4
    kur0d3s  
       Nov 1, 2024
    直接 stream 模块转发 tcp 或者直接 dnat ?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5430 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    ♥ Do have faith in what you're doing.