【发布时间】:2018-07-03 10:42:40
【问题描述】:
我在 Nginx 上运行 websocket 服务器时遇到问题。这是我的 Nginx default.conf:
upstream websocket {
server xx.xx.xx.xx:8080;
}
server {
listen 80;
listen [::]:80;
server_name domain.com *.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name domain.com *.domain.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location /ws {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
我在 chrome 中收到以下错误:
(索引):2 WebSocket 连接到“wss://xx.xx.xx.xx/ws:8080”失败:连接建立错误:net::ERR_CERT_COMMON_NAME_INVALID
我认为这与证书 (SSL) 有关,但我真的不知道如何解决这个问题!
提前致谢!
编辑:
我的 index.php 文件是
<script>
var conn = new WebSocket('wss://xx.xx.xx.xx/ws');
conn.onopen = function(e) {
console.log("Connection established!");
};
</script>
当我将 xx.xx.xx.xx 更改为 domain.com 时,我收到握手错误代码 504。
顺便说一句,我正在通过 php (php server.php) 运行一个 websocket 服务器,并按照以下示例使用棘轮:http://socketo.me/docs/hello-world
【问题讨论】: