大网数据广告活动
服务器运维问答

Trying to proxy HTTPS, but getting: An unexpected TLS packet was received

· 52CE 我爱测

There is a HTTPS server on one port (5006). I'd like to make it available on 35001 and serve other things on the same 35001 too (by adding locations like /app , /auth , /admin , etc.). Server is auth-server.org.local . Trying jus…

问题原文

原帖链接 · Velkan · CC BY-SA 3.0

There is a HTTPS server on one port (5006). I'd like to make it available on 35001 and serve other things on the same 35001 too (by adding locations like /app, /auth, /admin, etc.).

Server is auth-server.org.local. Trying just to add a port:

server {
    listen 35001;
    location / {
        proxy_pass       https://auth-server.org.local:5006;
    }
}

Output:

$ curl -k -X GET https://auth-server.org.local:5006
<h1>My auth server</h1>

$ curl -k -X GET https://auth-server.org.local:35001
curl: (35) gnutls_handshake() failed: An unexpected TLS packet was received.

Why 35001 doesn't work? What am I missing? I've used this guide: https://www.nginx.com/resources/admin-guide/nginx-https-upstreams/

已采纳解答

原帖链接 · Tero Kilkanen · CC BY-SA 3.0

Your virtual server is a HTTP server, therefore it doesn't work with https connection attempts.

In order to make it HTTPS, you need to have this configuration:

server {
    listen 35001 ssl;
    server_name example.com;

    ssl_certificate /path/to/ssl/certificate;
    ssl_certificate_key /path/to/ssl/certificate;

    location / {
        proxy_pass https://auth-server.local:5006;
    }
}

Alternatively you can set up an nginx stream proxy, which simply passes the TCP stream to backend, so that nginx does not perform SSL termination:

stream {
    server {
        listen 35001;
        proxy_pass auth-server.local:5006;
    }
}

This has to be outside the http context.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。