webSocket的接口使用域名:
ws://xxx.xx.com/rykj-large/send/questionSocket/1676154373386858498
访问不了。改成服务器IP+端口可以访问。
解决:
在Nginx的配置文件中负载这个ip地址的服务器中加上文章来源:https://www.toymoban.com/news/detail-797660.html
proxy_set_header Host $proxy_host;
proxy_set_header Upgrade 'websocket';
proxy_set_header Connection 'Upgrade';
完整的Nginx配置是文章来源地址https://www.toymoban.com/news/detail-797660.html
server {
listen 80;
server_name xxx.xx.com;
location / {
root /home/nginx/html/ry_persionalchat_ui;
try_files $uri $uri/ /index.html late;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT';
add_header 'Access-Control-Allow-Headers' *;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
if ($request_method = 'OPTIONS') {
return 204;
}
}
location /rykj-large/ {
proxy_pass http://192.168.56.10:8085;
proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade 'websocket';
proxy_set_header Connection 'Upgrade';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
到了这里,关于webSocket接口使用域名访问不了的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!