客户端请求套接字URL为http://127.0.0.1:81/chat。套接字服务器url为http://127.0.0.1:19968/,因此我使用nginx进行重写,尽管我请求http://127.0.0.1:81/chat返回http状态码为101,但是套接字侦听envent无效并且无法发送消息
我从nignx网站进行了搜索,但未找到任何内容。
如果我删除位置1配置,则请求http://127.0.0.1:81/chat重新操作 404,为什么?
这是我的nignx配置:
upstream socket_nodes {
ip_hash;
#server srv1.app.com:5000 weight=5;
#server srv2.app.com:5000;
#server srv3.app.com:5000;
server 127.0.0.1:19968;
}
server {
listen 81;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root "C:/Users/najin/Desktop/docker/docker/html/";
#root "D:/phpStudy/PHPTutorial/WWW/PhalApi/";
//location 1
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://socket_nodes;
index index.html index.htm index.php l.php;
autoindex on;
}
//location 2
location /chat {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://socket_nodes;
#if (!-e $request_filename) {
# rewrite ^/ / break;
#}
rewrite ^/chat / last;
index index.html index.htm index.php l.php;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
当我请求http://127.0.0.1:81/chat时,回复:
请求网址:ws:// localhost:81 / socket.io /?EIO = 3&transport = websocket
请求方法:GET
状态码:101个交换协议
但是客户端套接字侦听器不起作用并且无法发送消息。当我什么也不发送时。
谢谢。