如何在春季启动时在apache2中为嵌入式tomcat服务器配置反向代理



我正在尝试为spring引导应用程序配置反向代理,但它不起作用。它提供来自www/example.com的html页面,而不是来自spring-boot应用程序的内容。

这是我的应用程序属性

server.address=127.0.0.1
server.port=8080
server.servlet.context-path=/
server.use-forward-headers=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto

这是我的示例com.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ProxyPreserveHost On
ServerName example.com
ServerAlias www.example.com
Redirect / https://www.example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>    
SSLEngine On
SSLProxyEngine On
ServerName example.com
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf    
</VirtualHost>

我想你只是错过了

ServerAlias www.example.com

在https虚拟主机配置中。

事实证明,有一个名为example.com-le-sl.conf的文件正在覆盖example.com.conf中的配置,所以我只是从example.com-les-sl.conf中复制了配置,它就起了作用。我的猜测是example.com-le-sl.conf是在我添加ssl证书时创建的。

最新更新