V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
saleacy
V2EX  ›  NGINX

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

  •  
  •   saleacy · 136 天前 · 1540 次点击
    这是一个创建于 136 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我先在 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/;
    }
    }
    }
    saleacy
        1
    saleacy  
    OP
       136 天前
    害怕了兄弟们,不敢睡觉了 i😨
    saleacy
        2
    saleacy  
    OP
       136 天前
    包括其他目录,就 ctl 后缀的文件报 502 错误,wget 也是 502 ,其他后缀都能正常访问,用 wget 保存。
    saleacy
        3
    saleacy  
    OP
       136 天前
    .ctl 后缀的文件访问都是 502😨
    heqing
        4
    heqing  
       136 天前
    在 172.18.231.93 上 strace 一下 nginx 进程,看看是哪里出错了
    hefish
        5
    hefish  
       136 天前
    看起来是有些玄幻啊。。。 看看 error.log 呢。。。
    saleacy
        6
    saleacy  
    OP
       136 天前
    在 172.18.231.93 上面用 wget curl 能读到通过 nginx 代理发布后的.ctl 后缀的文件
    flynaj
        7
    flynaj  
       136 天前 via Android
    打开详细日志,看日志。
    NessajCN
        8
    NessajCN  
       136 天前   ❤️ 1
    你看一下是不是你那些能访问的文件都在 /etc/nginx/mime.types 里列着,而 ctl 没在里面
    xinge666
        9
    xinge666  
       136 天前   ❤️ 1
    看一下 /etc/nginx/mime.types
    saleacy
        10
    saleacy  
    OP
       136 天前
    saleacy
        11
    saleacy  
    OP
       136 天前
    saleacy
        12
    saleacy  
    OP
       136 天前
    确实是/etc/nginx/mime.types 的问题 感谢各位的帮助
    carlinglm
        13
    carlinglm  
       136 天前
    看下 error 日志
    zuotun
        14
    zuotun  
       136 天前   ❤️ 1
    只要设置了 `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
        15
    saleacy  
    OP
       123 天前
    @zuotun 感谢分享帮助 问题已解决
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2823 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:23 · PVG 14:23 · LAX 23:23 · JFK 02:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.