我为我的应用程序配置了以下Nginx。支持Nginx的websocket。我还提到了配置。
upstream app {
ip_hash;
server localhost:8062;
}
server {
server_name app.com;
location / {
proxy_pass http://app/;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/app.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/app.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
它与http和本地地址完美配合。但是在通过域的https地址连接websocket时,仍然给我以下错误。
WebSocket connection to 'wss://app.com/chat/6110EA/' failed: Error during WebSocket handshake: Unexpected response code: 200
我现在已经将我的域指向Cloudflare,并且也使用了它的SSL。
请让我知道我在哪里有问题或配置有问题。
谢谢