繁体   English   中英

如何在 spring 引导中为嵌入式 tomcat 服务器在 apache2 中配置反向代理?

[英]How to configure reverse proxy in apache2 for embedded tomcat server in spring boot?

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

这是我的 application.properties

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-ssl.conf 的文件覆盖了 example.com.conf 中的配置,所以我只是从 example.com-le-ssl 中的 example.com.conf 中复制了配置.conf 并且它起作用了。 我的猜测是 example.com-le-ssl.conf 是在我添加 ssl 证书时创建的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM