我有一台 Azure VM,其中运行着 apache2,其配置如下,
<VirtualHost *:80>
ServerName .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 .com
ProxyRequests On
SSLProxyEngine On
ProxyPass / http://127.0.0.1:4003/
ProxyPassReverse / http://127.0.0.1:4003/
SSLEngine On
SSLCertificateFile /etc/ssl/.crt
SSLCertificateKeyFile /etc/ssl/.key
SSLCertificateChainFile /etc/ssl/.ca-bundle
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
正在运行的docker容器有此端口映射
0.0.0.0:4003->80/tcp, :::4003->80/tcp, 0.0.0.0:4004->443/tcp, :::4004->443/tcp
当流量通过端口 80 到达服务器时,一切都很好,Proxypass 在 Apache 配置中发挥作用,并将流量引导至属于该容器的 4003。
问题是当我通过 HTTPS 浏览网站时,出现了问题,流量通过端口 443 并再次转发到 4003,但这次 docker 容器没有响应,我不确定发生了什么,为什么在 Apache 端口 80 上可以工作,而为什么在端口 443 上不工作?
NGINX 配置的情况类似,即使现在我已经为端口 443 进行了不同的映射。
server {
listen 80;
listen [::]:80;
server_name .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 .com;
ssl on;
ssl_certificate /etc/ssl/cert_chain.crt;
ssl_certificate_key /etc/ssl/.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;
}
}