nginx配置,websocket代理,位置,如果

时间:2013-03-05 23:18:15

标签: nginx websocket config

我有一个非常具体的nginx配置问题:

我需要nginx:

  • 代理websocket连接@ /
  • 使用index.html响应标准http请求@ /

这是我能得到的最接近的:

  location = / {
   if ($http_upgrade != "websocket") {
    # Here lies my problem:
    # This returns a http: 302 where i just need it to return the contents
    # of index.html
    return https://admin.permaconn.com/index.html;
   }

   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
   proxy_pass http://localhost:8080;
  }

我正在使用我的应用程序进行结构更改,使用nodejs作为前端代理,将nginx用作前端代理。

我必须以这种方式配置nginx,因为许多程序已经安装了设备(也就是传统设备)的预期行为。

1 个答案:

答案 0 :(得分:11)

您滥用return指令。

location = / {
    index index.html;

    if ($http_upgrade = "websocket") {
        proxy_pass http://localhost:8080;  
    }

    proxy_http_version 1.1;
    proxy_set_header Upgrade websocket;
    proxy_set_header Connection upgrade;
}

文档:

相关问题