问题描述
我正在尝试隐藏已部署容器的端口并使用 ProxyPass 保留原始 url。 我可能配置错误,因为不是简单地保留原始地址,而是重定向到容器地址(example.com:8014 而不是保留 subdomain.example.com)。 HTTP 响应是:301 Moved Permanently(来自服务工作者)。
这是包含代理的虚拟主机:
<VirtualHost *:80>
ServerName subdomain.example.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =subdomain.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName subdomain.example.com
ServerAlias subdomain.example.com
LoadModule proxy_http_module modules/mod_proxy_http.so
SSLProxyEngine On
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/subdomain.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/subdomain.example.com/privkey.pem
ProxyPreserveHost On
ProxyPass / https://example.com:8014/
ProxyPassReverse / https://example.com:8014/
</VirtualHost>
这是容器内的虚拟主机:
<VirtualHost *:80>
ServerName example.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com:8014
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin@example.com
ServerName example.com
<Directory /var/www/html>
AllowOverride All
</Directory>
SSLEngine On
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-poly1305:ECDHE-RSA-CHACHA20-poly1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder off
SSLSessionTickets off
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/fullchain.pem
SSLCertificateKeyFile /etc/apache2/privkey.pem
</VirtualHost>
容器端口映射如下:80->8012、443->8014。
我的目标是在不更改地址的情况下使用 subdomain.example.com 访问 example.com:8014。 此外,我什至不确定为什么在使用 example.com:8012 时我没有被重定向到端口 8014 上的 https。 问题必须出在容器虚拟主机上,因为它正在生成 301 状态代码。
解决方法
配置工作正常。 发生这种情况时,我建议清除谷歌浏览器的缓存。