【发布时间】:2017-10-30 15:26:24
【问题描述】:
我有node.js 应用程序,由NGINX 提供服务。我无法连接 socket.io 并不断收到 404 POST 请求以建立连接。
它在本地工作,所以它一定是NGINX 问题。
# HTTP - redirect all requests to HTTPS:
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
# HTTPS - proxy requests on to local Node.js app:
server {
listen 443 ssl http2;
server_name example.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://127.0.0.1:8080;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
感谢您的帮助。
【问题讨论】:
-
您使用的是哪个 nginx 版本?它可能还不支持 HTTP2。
-
最新版本。 HTTP2 工作正常,这是用于 socekts 的 NGINX 配置的问题。
-
你有没有初始化 socket.io 并设置为这样监听: var io = app.io; io.listen(服务器); ?
-
@iubema 这正是我所拥有的。
标签: node.js nginx https socket.io http2