本文介绍了Spring Boot静态内容在本地可以正常工作,但当我推送到VPS服务器时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在本地可以正常运行的Spring Boot,并且访问时没有问题:。每当我上传到运行Cpanel / WHM的VPS时,当我尝试访问其中example.com是我的网站。我没有访问我的主页的问题,除了静态内容没有加载。任何想法,我需要在WHM / Cpanel配置中进行更改以获取Spring Boot的静态内容,以停止出现以下错误:

I have a spring boot that runs fine locally and I have no problems accessing: http://localhost:8080/staticlayouts/blah.html. Whenever I upload to my VPS running Cpanel/WHM i get the following when I try to access http://www.example.com/staticlayouts/blah.html where example.com is my website. I Have no issues accessing my main page, other than static content is not loading. Any ideas what I need to change in WHM/Cpanel configuration to get the static content of spring boot to stop getting the following error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /staticlayouts/blah.html.

Reason: DNS lookup failure for: localhost:8080staticlayouts

Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.


推荐答案

经过数小时的浪费时间,我尝试了毫无价值的事情,问题是因为我的Apache httpd配置。在我的vhost.config文件中,我有以下内容:

After hours of wasting my time trying worthless things, the problem was because of my apache httpd configuration. In my vhost.config file I had this:

ProxyPreserveHost on
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080

我需要这个(网址上的斜杠):

ProxyPreserveHost on
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

此网址是一个很好的参考:

This url is a great reference: https://medium.com/@codebyamir/using-apache-as-a-reverse-proxy-for-spring-boot-embedded-tomcat-f704da73e7c8

这篇关于Spring Boot静态内容在本地可以正常工作,但当我推送到VPS服务器时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:59