server {
listen 9191;
server_name xxx;
location / {
root arcroomsys;
index index.html;
try_files $uri $uri/ /index.html;
}
#此处为ws协议代理
location /wsapi {
proxy_pass http://192.168.0.112:8080/Room;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
以下是两种不同方式的连接:
var socket = new SockJS(
`http://${wsapiBaseUrl}/wsDeviceOperation?Authorization=${this.token}`
);
1、wsapiBaseUrl 的内容为:127.0.0.1:8080/wsapi 经过Nginx代理后,将会替换为:
http://192.168.0.112:8080/Room/wsDeviceOperation?Authorization=${this.token}
=========================================================================
this.websock1 = new WebSocket(`ws://${wsapiBaseUrl}/Websocket/${this.fonduuid}`);
2、wsapiBaseUrl 的内容为:127.0.0.1:8080/wsapi 经过Nginx代理后,将会替换为:
http://192.168.0.112:8080/Room/Websocket/${this.fonduuid}