gpt4 book ai didi

nginx 配置、websocket 代理、位置、if

转载 作者:行者123 更新时间:2023-12-04 18:38:33 24 4
gpt4 key购买 nike

我有一个非常具体的 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。

最佳答案

您滥用了 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;
}

文档:

关于nginx 配置、websocket 代理、位置、if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15236021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com