对于我的一个客户项目,我有一个域名abc.my-app.com。我的服务器公共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到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>`
答案 0 :(得分:0)
我终于开始工作了。虽然这是正确的方法但不确定。 在Spring启动应用程序中,我将端口80的重定向配置为端口443。 Apache2从443重定向到我在端口8443上运行的应用程序。