gpt4 book ai didi

nginx - 在 nginx 后面运行 Spring Boot 应用程序

转载 作者:行者123 更新时间:2023-12-04 02:15:07 25 4
gpt4 key购买 nike

我的服务器上启动并运行了一个 Spring Boot + MVC 应用程序,它绑定(bind)到 http://localhost:8000 .

有一个 nginx 代理(或者它是一个反向代理,不确定名称)在端口 80 和 443 上监听外部世界。根 (/) 将正确解析,但它下面的任何内容都不会解析并导致404 错误(/someControllerName/action、/images/、/css/)。

我有这个作为我的配置:

upstream jetty {
server localhost:8000;
}

server {
listen 80;
server_name domain.com;
return 301 http://www.domain.com$request_uri;
}

server {
listen 443;
server_name domain.com;
ssl_certificate /etc/nginx/ssl/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;
return 301 https://www.domain.com$request_uri;
}

server {
listen 80 default_server;
listen 443 ssl;

root /usr/share/nginx/html;
index index.html index.htm;

server_name www.domain.com localhost;

#ssl on;
ssl_certificate /etc/nginx/ssl/ssl-unified.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
proxy_pass $scheme://jetty/$request_uri;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
try_files $uri $uri/ =404;
}
}

很感谢任何形式的帮助。

最佳答案

你不能合并proxy_passtry_files以您尝试过的方式。正如您配置中的注释所述,try_files指令使 nginx 查找与 URI 匹配的文件,然后查找与 URI 匹配的目录。如果没有找到,它会以 404 响应。您可以阅读有关 try_files 的更多信息。在 nginx documentation .

从您的问题中不清楚您需要使用 try_files所以修复配置的最简单方法是删除 try_files线。

关于nginx - 在 nginx 后面运行 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com