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

nginx 代理 websocket 出现 404 错误

  •  
  •   Achilless · 2019-11-04 10:32:55 +08:00 · 3290 次点击
    这是一个创建于 1606 天前的主题,其中的信息可能已经有所发展或是发生改变。

    部署的是 django,uwsgi。websocket 用的 channels 其他功能正常,只有 websocket 报 404 错误,

    具体配置文件和代码我放在了博客: https://www.ksprd.top/blog/46/

    有没有趟过坑的大佬~

    5 条回复    2019-11-04 14:44:08 +08:00
    lazyfighter
        1
    lazyfighter  
       2019-11-04 11:28:10 +08:00
    问问题贴个博客是什么鬼啊,404 找不到呗
    Achilless
        2
    Achilless  
    OP
       2019-11-04 11:33:45 +08:00
    @lazyfighter 放代码呗,所以问题就是为啥 404 呗
    anthoy
        3
    anthoy  
       2019-11-04 13:29:30 +08:00
    我使用是用 uwsgi 启动 django,daphne 启动 django-channel,两个使用不同的端口,nginx 反向代理 /和 /ssh,正常使用
    你这里的可能是这个:
    ```bash
    location /ssh {
    uwsgi_pass 127.0.0.1:8080;
    include /opt/clic_env/plat/uwsgi_params;
    ```
    你确定你的 uwsgi 同时启动了 django 和 django-channels ?你可以使用尝试不使用 uwsgi_pass 转发 websocket 或者不用 nginx,直接调试下 uwsgi
    37Y37
        4
    37Y37  
       2019-11-04 13:33:19 +08:00
    nginx 缺少了这个配置

    ```shell
    map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
    }
    ```

    另外看你写的 webssh,推荐一下: https://ops-coffee.cn/s/a3eJjVTtuUjzwyk21nTBqQ
    Achilless
        5
    Achilless  
    OP
       2019-11-04 14:44:08 +08:00
    @anthoy 感谢,才知道原来还要单独起一个 websocket 进程。。所以那就是 django 默认的服务器是两个都打开的。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   987 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:28 · PVG 04:28 · LAX 13:28 · JFK 16:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.