我有node.js
应用程序,它是由NGINX
服务。我无法连接socket.io,并继续获取404请求建立连接的POST请求。Socket.io与NGINX和https2
它的工作在本地,所以它必须是一个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。 – Nevertheless
这是最新版本。 HTTP2工作正常,这对于socekts的NGINX配置是一个问题。 –
你是否已经初始化了socket.io并设置为这样听: var io = app.io; io.listen(服务器); ? – iubema