簡體   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