【问题标题】:How to configure reverse proxy in apache2 for embedded tomcat server in spring boot?如何在 apache2 中为 Spring Boot 中的嵌入式 tomcat 服务器配置反向代理?
【发布时间】:2021-01-12 10:51:51
【问题描述】:

我正在尝试为 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>

【问题讨论】:

  • 你的日志文件有显示吗?
  • @alexzimmer96 不,日志文件中没有与代理相关的内容

标签: java spring-boot apache2 reverse-proxy


【解决方案1】:

我认为你只是错过了

ServerAlias www.example.com

在 https 虚拟主机配置中。

【讨论】:

    【解决方案2】:

    事实证明,有一个名为 example.com-le-ssl.conf 的文件覆盖了 example.com.conf 中的配置,所以我只是将 example.com.conf 中的配置复制到了 example.com- le-ssl.conf 并且有效。我的猜测是 example.com-le-ssl.conf 是在我添加 ssl 证书时创建的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 2014-11-13
      • 2019-10-11
      • 1970-01-01
      • 2021-07-18
      • 2021-03-03
      • 2021-09-12
      相关资源
      最近更新 更多