java - 如何在apache2中为spring boot中的嵌入式tomcat服务器配置反向代理?
问题描述
我正在尝试为 spring boot 应用程序配置反向代理,但它不起作用。它从 www/example.com 提供 html 页面,而不是从 Spring Boot 应用程序提供内容。
这是我的 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
这是我的 example.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>
解决方案
事实证明,有一个名为 example.com-le-ssl.conf 的文件覆盖了 example.com.conf 中的配置,所以我只是将 example.com.conf 中的配置复制到了 example.com-le-ssl .conf 并且它起作用了。我的猜测是 example.com-le-ssl.conf 是在我添加 ssl 证书时创建的。
推荐阅读
- typescript - 联合类型功能“重载”不起作用
- reactjs - 我应该如何在我的 React 应用程序中对 Google Cloud Function 进行身份验证?
- java - 如何根据java中的唯一列合并csv文件
- java - 从 AWS 凭证提供程序获取安全令牌
- python - 如何在 Django 中动态查询(?)?
- sql - 如何在具有管理权限的 sql server 中找到角色和权限
- vb.net - 如何在 VB.NET 中使对象跟随鼠标?
- java - 如果其他条件无法正常工作
- python - python循环列表索引超出范围
- linux-kernel - 如何在两个模块之间导出变量?