我正在运行Nginx服务器。我已经安装了certbot的证书。 所以现在它对于Http和Https都可用。 现在的问题是我无法访问其中的websocket。 它给出了ws不安全的错误,您正在尝试使用https访问它。尝试使用WSS而不是WS。我无法使用WS。 我可以做某种代理使WS与https一起工作吗?
完整错误为: “ https://chain.com/”上的页面已通过HTTPS加载,但尝试连接到不安全的WebSocket端点“ ws://123.3.6.5:7546 /”。该请求已被阻止;该端点必须可以通过WSS使用。
我的nginx配置是..
server{
server_name chain.com www.chain.com;
root /home/ubuntu/chain.com/app;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/chain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/chain.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
location / {
proxy_pass http://localhost:7546/; #7546 is the websocket port
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
try_files $uri /index.html =404;
}
}