部署在Tomcat上的Spring Boot应用程序创建错误的URL [英] Deploed Spring Boot application on Tomcat create bad URLS

查看:65
本文介绍了部署在Tomcat上的Spring Boot应用程序创建错误的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Spring Boot应用程序和它是用于移动应用程序的REST API.因此它可以在本地正常运行,但是在tomcat远程服务器上运行后,它会出现问题.所以,这是我在tomcat应用程序管理器中的应用程序

I have Spring Boot application& It is REST API for mobile app. So it works ok localy, but after deply on tomcat remote server, it have problems. So, here my app in tomcat application manager

这里是属性文件

server.forward-headers-strategy=framework


spring.freemarker.expose-request-attributes=true
spring.freemarker.suffix= .ftl
# location of the swagger json


spring.data.mongodb.authentication-database=aibolitDB
spring.data.mongodb.username=admin
spring.data.mongodb.password=admin
spring.data.mongodb.database=aibolitDB
spring.data.mongodb.port=27017
spring.data.mongodb.host=localhost

springdoc.swagger-ui.path=/swagger-ui-aibolit.html



spring.servlet.multipart.max-file-size=256MB
spring.servlet.multipart.max-request-size=256MB
spring.servlet.multipart.enabled=true

app.url.base=http://aibolitbackend.unitbeandev.com/

ub.vet.jwtSecret= bezKoderSecretKey
ub.vet.jwtExpirationMs= 86400000

logging.level.org.springframework.web = trace
logging.level.org.apache = trace

何时我尝试发送api请求,这给了我一个错误

And When I try to send api request, it gives me an error

如您所见,它尝试在/AibolitBackend/路径中查找这是我的NGINX属性

As you can see, it try to find in /AibolitBackend/ path Here my NGINX properties

 location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080/AibolitBackend/;
    #       try_files $uri $uri/ =404;
    }

我忘记设置什么?我需要向Tomcat主机添加一些东西吗?而且我无法在Base/path上创建它,因为这里有3个应用程序.

What I forgot to set up? Need I add some thing to Tomcat hosts?? And I cant to make it on Base / path, because here will by 3 apps.

推荐答案

您在同一位置混合了 try_files proxy_pass 指令.那没有任何意义.通常要通过nginx提供静态文件并将其他请求传递给后端,您应该使用类似

You have a weird mix of try_files and proxy_pass directives in the same location. That doesn't make any sense. Usually to serve static files with nginx and pass other requests to the backend you should use something like

location /
    # First attempt to serve request as static file, then pass request to the backend
    root <set_correct_root_for_your_static_files_here!>;
    try_files $uri @tomcat;
}
location @tomcat {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8080;
}

通过 proxy_pass http://127.0.0.1:8080/AibolitBackend/; ,您可以将诸如/some/path 之类的任何请求转换为/AibolitBackend/some/path ,然后再转到后端.我不明白您要使用此/AibolitBackend/前缀实现什么.

With proxy_pass http://127.0.0.1:8080/AibolitBackend/; you get any request like /some/path transformed to /AibolitBackend/some/path before going to the backend. I didn't understand what do you want to achieve with this /AibolitBackend/ prefix.

这篇关于部署在Tomcat上的Spring Boot应用程序创建错误的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆