我正在使用 Node.js 和 NGINX 提供一个应用程序。我使用 LetsEncrypt 保护 NGINX,并使用 pm2 在服务器上运行我的节点应用程序(使用 NGINX 作为反向代理)。
我的网站不会加载任何内容(426 错误 - 需要升级),但我可以使用以下暂存器进行连接:
var port = 443;
var ws = new WebSocket("wss://mywebsite.com:" + port);
ws.onopen = function() {
console.log("Connected");
}
ws.onmessage = function(comment) {
console.log(JSON.parse(comment.data));
}
Run Code Online (Sandbox Code Playgroud)
这是 NGINX 设置:
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name mywebsite.com www.mywebsite.com;
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen [::]:443 …Run Code Online (Sandbox Code Playgroud)