Apache2 重定向到 https
Apache2 redirect to https
对于我的一个客户项目,我有一个域名 abc.my-app.com。我的服务器 public IP 是 x.y.z.a .
我开发了一个 Spring 基于引导的应用程序。在应用程序中,我配置了从 http 端口 8088 到 https 8443 的自动重定向。
该应用程序可以作为 https://x.y.z.a:8443/ 毫无问题地访问。
当以 http://x.y.z.a:8088 访问时,应用程序也会重定向到 https
在浏览器中。
参考 https://drissamri.be/blog/java/enable-https-in-spring-boot/ 我是如何配置的。
我的服务器上也安装了 apache 2.4.18 版本。当我的应用程序从浏览器作为 https://abc.my-app.com to https://abc.my-app.com:8443 访问时,我已将虚拟主机配置为能够重定向到 https。
但是,如果用户访问 http://abc.my-app.com(没有 https),apache 不会重定向到我在 https 上的应用程序。
如何让 Apache 从 http://abc.my-app.com 重定向到 https://abc.my-app.com?
我的虚拟主机配置如下:
<VirtualHost *:80 *:8080 *:443>
ServerAdmin webmaster@xyzc
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName Off
ProxyPreserveHost On
# Servers to proxy the connection, or
# List of application servers Usage
ProxyPass / https://x.y.z.a:8443/
ProxyPassReverse / https://x.y.z.a:8443/
ServerName ip-x-y-z-a
</VirtualHost>`
我终于让它工作了。不确定这是正确的方法。
在 Spring 引导应用程序中,我配置了从端口 80 到端口 443 的重定向。
Apache2 在端口 8443 上从 443 重定向到我的应用程序 运行。
对于我的一个客户项目,我有一个域名 abc.my-app.com。我的服务器 public IP 是 x.y.z.a .
我开发了一个 Spring 基于引导的应用程序。在应用程序中,我配置了从 http 端口 8088 到 https 8443 的自动重定向。 该应用程序可以作为 https://x.y.z.a:8443/ 毫无问题地访问。 当以 http://x.y.z.a:8088 访问时,应用程序也会重定向到 https 在浏览器中。
参考 https://drissamri.be/blog/java/enable-https-in-spring-boot/ 我是如何配置的。
我的服务器上也安装了 apache 2.4.18 版本。当我的应用程序从浏览器作为 https://abc.my-app.com to https://abc.my-app.com:8443 访问时,我已将虚拟主机配置为能够重定向到 https。
但是,如果用户访问 http://abc.my-app.com(没有 https),apache 不会重定向到我在 https 上的应用程序。
如何让 Apache 从 http://abc.my-app.com 重定向到 https://abc.my-app.com?
我的虚拟主机配置如下:
<VirtualHost *:80 *:8080 *:443>
ServerAdmin webmaster@xyzc
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName Off
ProxyPreserveHost On
# Servers to proxy the connection, or
# List of application servers Usage
ProxyPass / https://x.y.z.a:8443/
ProxyPassReverse / https://x.y.z.a:8443/
ServerName ip-x-y-z-a
</VirtualHost>`
我终于让它工作了。不确定这是正确的方法。 在 Spring 引导应用程序中,我配置了从端口 80 到端口 443 的重定向。 Apache2 在端口 8443 上从 443 重定向到我的应用程序 运行。