You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache/Nginx配置HTTPS反向代理至Docker容器无响应,但HTTP正常的问题求助

Apache/Nginx配置HTTPS反向代理至Docker容器无响应,但HTTP正常的问题求助

大家好,我现在遇到一个反向代理的问题,折腾了好久没搞定,想请教下各位大佬。

我的环境是Azure虚拟机,上面先后跑过Apache2和Nginx,同时有个Docker容器在运行,容器的端口映射如下:

0.0.0.0:4003->80/tcp, :::4003->80/tcp, 0.0.0.0:4004->443/tcp, :::4004->443/tcp

先说说Apache的情况:
我配置了两个VirtualHost,80端口的代理指向http://127.0.0.1:4003/,外部通过HTTP访问网站完全正常。但443端口的VirtualHost不管是代理到http://127.0.0.1:4003/还是后来改成http://127.0.0.1:4004/,外部用HTTPS访问时容器都没有响应,完全搞不懂哪里出了问题。

我的Apache配置如下:

<VirtualHost *:80>
ServerName example.com
ProxyRequests On
ProxyPass        / http://127.0.0.1:4003/
ProxyPassReverse / http://127.0.0.1:4003/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:443>
ServerName example.com
ProxyRequests On
SSLProxyEngine On
ProxyPass        / http://127.0.0.1:4003/
ProxyPassReverse / http://127.0.0.1:4003/
SSLEngine On
SSLCertificateFile /etc/ssl/example.crt
SSLCertificateKeyFile /etc/ssl/example.key
SSLCertificateChainFile /etc/ssl/example.ca-bundle
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

后来换成Nginx尝试,情况几乎一样:80端口代理到http://localhost:4003一切正常,但443端口代理到http://localhost:4004时,容器还是没有响应。我的Nginx配置如下:

server {
listen 80;
listen [::]:80;
server_name example.com;
#return 301 https://$server_name$request_uri;
location / {
proxy_pass http://localhost:4003;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
client_max_body_size 1024M;
server_name example.com;
ssl on;
ssl_certificate /etc/ssl/cert_chain.crt;
ssl_certificate_key /etc/ssl/example.key;
location / {
proxy_pass http://localhost:4004;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

我现在实在搞不明白:为什么HTTP反向代理完全正常,但HTTPS不管用Apache还是Nginx都无法让容器响应?已经确认Docker的端口映射是正确的,4004确实对应容器的443端口。会不会是容器内部的配置有问题?或者代理服务器这边的SSL相关设置遗漏了什么?

麻烦各位帮忙分析下可能的原因,或者给我一些排查的方向,谢谢大家!

备注:内容来源于stack exchange,提问作者Majid Khan Mohmand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 10:19:28