gpt4 book ai didi

nginx - 使用 nginx 作为 websocket 连接的代理

转载 作者:行者123 更新时间:2023-12-02 17:23:14 25 4
gpt4 key购买 nike

如何使用 nginx 作为 websocket 的代理?如果我需要从 clientSite.com(javascript)连接到 socketSite.com:port而且我不会显示用户的链接“socketSite.com:port”

我可以使用 nginx 代理从/到 websocket 服务器重定向请求吗?

最佳答案

当然可以!使用以下配置:

location /myHandler{
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header HOST $host;
proxy_set_header X_Forwarded_For $remote_addr;
proxy_pass http://localhost:8880;
proxy_redirect default;
client_max_body_size 1000m;
}

我使用 spring websocket。 /myHandler 是我创建 websocket 连接的 URL,http://localhost:8880; 是我的 Tomcat 服务器地址。 Nginx 服务器和 Tomcat 在同一台机器上运行。

关于nginx - 使用 nginx 作为 websocket 连接的代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41093091/

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