![](/img/trans.png)
[英]Node.js socket.io cannot GET 404 not found with Nginx reverse proxy
[英]Socket.io not working with Nginx reverse proxy in front of Node.js
我的節點應用程序在端口3000上運行。然后,我使用nginx作為反向代理,以我域的SSL為應用程序提供服務:
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/server.chain.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我在客戶端用以下行初始化套接字:
var socket = io.connect('https://example.com/');
而在服務器端的這一行:
var io = socket_io()
app.io = io
但是,當我啟動我的應用程序時,會出現以下錯誤:
WebSocket connection to 'wss://example.com/socket.io/?EIO=3&transport=websocket&sid=jVNRhDOYJD20l9U-AAAA' failed: Error during WebSocket handshake: Unexpected response code: 502
您知道如何解決此錯誤嗎?
本文介紹了在Kaazing WebSocket服務器之前使用nginx作為rev-proxy。
https://kaazing.com/kaazing-and-nginx-the-best-of-both-worlds/
本文中描述的配置可能與使用NodeJS作為服務器非常相似。 希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.