spring - NGINX - Spring Boot 应用程序(“/etc/nginx/html/index.html”未找到)
问题描述
所以我有我想放在 nginx 后面的 spring boot 应用程序,问题是我在访问 localhost 时连接被拒绝。
我的 nginx 配置如下所示:
server {
listen 80;
server_name workaround;
charset utf-8;
access_log off;
location / {
proxy_pass http://172.19.0.3:8080/workaround;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
}
}
我正在运行的内容:
访问 localhost 时我得到的响应
404 未找到。当它在我的 docker compose 文件中时,它怎么会寻找一些 etc/nginx/html/index:
nginx:
container_name: workaround-nginx
image: nginx:1.15.12-alpine
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
depends_on:
- workaround
我的配置有什么问题?如何正确访问我的 SB 应用程序?
- 我曾尝试使用 localhost 而不是无效的 IP 芽。因为它使用了应用程序未运行的 nginx ip。
- 我正在考虑以某种方式重写 nginx bud 的默认配置,我什至如何从 dockerfile 做到这一点,那么当卷已经设置了映射时,为什么我必须被迫这样做。
解决方案
好的,我想通了,我什至设法修复它,以便它与具有哈希前缀的资源一起使用:
events {
worker_connections 1024;
}
http {
server {
listen 80;
charset utf-8;
access_log off;
try_files $uri $uri/ =404;
location / { #this still has to be here, otherwise i get ISE
proxy_pass http://workaround:8085/;
}
location ^~ { #this thing fixes hashes and resources
proxy_pass $scheme://workaround:8085/$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;
expires 30d;
}
}
}
推荐阅读
- .net - 通过 Microsoft Graph API 创建新的 AD B2C 用户
- android - 颤振语音识别语言环境de_DE不起作用
- json - 使用 json serde 在 hive 中加载 json 文件
- amazon-web-services - 最好扩展更少的大型实例还是更多的小型实例?
- ibm-mobilefirst - 问题 - 光标将焦点转移到基于 xcode 10.1 构建的 iOS 12 IPA 上的下一个文本框
- vb.net - 修改水晶报表中的参数值
- java - 如何从比屏幕大的视图的屏幕截图中创建位图?
- python - 为什么当我添加我用作参数的组时,由于 nonetype 没有属性而出现属性错误
- directus - 使用 git 升级 Directus 7 会导致使用时出错 - git pull origin
- .net - MVC5 应用程序在 IIS / Windows 2019 服务器上启动应用程序池时挂起