gpt4 book ai didi

ssl - 如何在 Nginx 节点服务器上配置 Websocket 安全(wss)?

转载 作者:行者123 更新时间:2023-12-04 22:37:55 29 4
gpt4 key购买 nike

我试图在我的 Nginx 服务器上配置一个 Websocket 代理,但不幸的是,我没有让它工作。我已经阅读了各种表格,但无法摆脱它。我认为这与客户端与服务器的连接有关。本地 om 我的电脑一切正常

客户端代码:

 var port = new osc.WebSocketPort({
url: "wss://circusfamilyprojects.nl/"
});

服务器代码:
var wss = new WebSocket.Server({
port: 8083
});


这是我在 Nginx 中的配置
 # custom code for hop by hop headers
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}


#custom code for connection with websocket this is the port on the server
upstream websocket {
server 178.62.209.37:8083;
}

server {

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/circusfamilyprojects.nl/fullchain.pem; # managed by Cert$
ssl_certificate_key /etc/letsencrypt/live/circusfamilyprojects.nl/privkey.pem; # managed by Ce$
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

root /var/www/html/vue/cfdomotica/server/public;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name circusfamilyprojects.nl www.circusfmailyprojects.nl; # managed by Certbot

location / {
proxy_pass http://websocket;
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;

}
}

server {
if ($host = www.circusfamilyprojects.nl) {
return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = circusfamilyprojects.nl) {
return 301 https://$host$request_uri;
} # managed by Certbot


listen 8080 ;
listen [::]:8080 ;
server_name circusfamilyprojects.nl;
return 404; # managed by Certbot
}

在我的浏览器中,我收到消息“状态代码:需要 426 升级”希望有人能帮助我,在此先感谢!

最佳答案

我自己解决了这个问题,将端口 443 的服务器 block 和 WebSocket 客户端的服务器 block 分开。我在端口 8086 上为客户端做了服务器 block 。

关于ssl - 如何在 Nginx 节点服务器上配置 Websocket 安全(wss)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61543967/

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