简体   繁体   English

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

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

I am trying to configure reverse proxy for spring boot app, but it is not working.我正在尝试为 spring 启动应用程序配置反向代理,但它不起作用。 It serves the html page from www/example.com instead of serving content from spring boot app.它提供来自 www/example.com 的 html 页面,而不是提供来自 spring 引导应用程序的内容。

Here is my application.properties这是我的 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

This is my example.com.conf这是我的例子。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>

I think you're just missing the我想你只是错过了

ServerAlias www.example.com

in the https virtualhost configuration.在 https 虚拟主机配置中。

As it turns out that there was file named example.com-le-ssl.conf that was overwriting the configuration in example.com.conf so, I just copied the configuration from example.com.conf in example.com-le-ssl.conf and it worked.事实证明,有一个名为 example.com-le-ssl.conf 的文件覆盖了 example.com.conf 中的配置,所以我只是从 example.com-le-ssl 中的 example.com.conf 中复制了配置.conf 并且它起作用了。 My guess is example.com-le-ssl.conf was created when I added ssl certificate.我的猜测是 example.com-le-ssl.conf 是在我添加 ssl 证书时创建的。

暂无
暂无

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

相关问题 如何获取apache2反向代理和tomcat服务器背后的客户端主机名? - How to get the clients host name behind apache2 reverse proxy and tomcat server? 如何为嵌入在我的 spring-boot 应用程序中的 Web 服务器(Tomcat)配置低级套接字属性? - How to configure low-level socket properties for a web server (Tomcat) embedded in my spring-boot application? 如何使用Spring Boot和嵌入式Tomcat配置此属性? - How do I configure this property with Spring Boot and an embedded Tomcat? 如何为 Spring Boot 应用程序配置嵌入式 Tomcat 虚拟主机? - how to configure Embedded Tomcat virtual host for Spring Boot Application? 带有嵌入式 Tomcat 的 Spring Boot 应用程序在请求 /contextPath 时不重定向到 https 而不使用尾部斜杠 - Spring Boot application with embedded Tomcat behind reverse proxy not redirecting to https when asking for /contextPath without trailing slash 在 spring-boot 中的嵌入式 apache tomcat 中配置“tomcat-server.xml”文件 - Configuring 'tomcat-server.xml' file inside of embedded apache tomcat in spring-boot 如何在不使用Spring启动和使用单独的Apache tomcat服务器的情况下在Spring WS中配置双向SSL连接? - How to configure two way SSL connection in Spring WS without using Spring boot and using separate Apache tomcat server? spring boot的嵌入式tomcat服务器如何加载外部“war”文件 - How load a external "war" file to the embedded tomcat server of spring boot 如何为客户端和服务器配置Spring Boot RestTemplate代理 - How to configure spring boot resttemplate proxy for client and server Spring启动为嵌入式服务器配置自定义jsessionid - Spring boot configure custom jsessionid for embedded server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM