2

我有一个非常具体的 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,因为许多程序已经安装了设备(又名旧版)的预期行为。

4

1 回答 1

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;
}

文件:

于 2013-03-06T14:43:49.843 回答