Linux -Nginx 遇到一个玄学问题!

148 天前
 saleacy
我先在 172.18.231.93 上面用 nginx 对外发布了静态资源,然后使用 10.211.128.198 做了七层转发,用着非常好,在 10.211.128.198 的网段可以请求到 172.18.231.93 的资源,今天出现了一个玄学问题!刚代理的 ctl 后缀文件代理后 nginx 访问直接报了 502 的错误。

https://imgur.com/a/dwI5njJ

grd 、png 、jpg 、txt 等等都能正常访问,就这个 ctl 后缀的文件访问都是 502 报错,见下图。

https://imgur.com/H9aVaRc





这是 10.211.128.198 的 nginx 配置:

user www-data;
worker_processes auto;
worker_cpu_affinity auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 65535;
use epoll;
# multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

gzip on;
server {
listen 9951;
server_name localhost;
server_tokens off;

location /modelosam/ {
proxy_pass http://172.18.231.93:10081/modelosam/;
}
}
}
1557 次点击
所在节点    NGINX
15 条回复
saleacy
148 天前
害怕了兄弟们,不敢睡觉了 i😨
saleacy
148 天前
包括其他目录,就 ctl 后缀的文件报 502 错误,wget 也是 502 ,其他后缀都能正常访问,用 wget 保存。
saleacy
148 天前
.ctl 后缀的文件访问都是 502😨
heqing
148 天前
在 172.18.231.93 上 strace 一下 nginx 进程,看看是哪里出错了
hefish
147 天前
看起来是有些玄幻啊。。。 看看 error.log 呢。。。
saleacy
147 天前
在 172.18.231.93 上面用 wget curl 能读到通过 nginx 代理发布后的.ctl 后缀的文件
flynaj
147 天前
打开详细日志,看日志。
NessajCN
147 天前
你看一下是不是你那些能访问的文件都在 /etc/nginx/mime.types 里列着,而 ctl 没在里面
xinge666
147 天前
看一下 /etc/nginx/mime.types
saleacy
147 天前
saleacy
147 天前
saleacy
147 天前
确实是/etc/nginx/mime.types 的问题 感谢各位的帮助
carlinglm
147 天前
看下 error 日志
zuotun
147 天前
只要设置了 `default_type application/octet-stream;` 不能被正确识别的文件就会作为文件流被直接下载 (比如静态服务器访问 index.php 就是这种情况, 不能识别但也不会报错)
502 是网关错误, 就是 nginx 访问 proxy_pass 获取到了非正常状态码 (4xx / 5xx), 有问题的应该是这里:
```
location /modelosam/ {
proxy_pass http://172.18.231.93:10081/modelosam/;
}
```
根据你的需求这里应该填 `http://172.18.231.93:10081;`, 你可以去看源服务器的日志, 实际上是请求 `{http://172.18.231.93:10081/modelosam}/modelosam/` 下的内容去了, 返回 404 所以 nginx 报 502 了.
一般来说 proxy_pass 都是不带路径的, 因为不少应用都是做成独立站点这样会产生很多不必要的问题.
saleacy
134 天前
@zuotun 感谢分享帮助 问题已解决

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/999837

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX