Open xiaoyi510 opened 3 months ago
21118 什么端口什么的 可以通过路径来转发? 比如 wss://xx/hbbs 转发到内部 127.0.0.1 21118 这样的端口 网页应该有操作空间
欢迎pr啊,我集成进来后没有细研究,主要是对js没能力
我也是懒人 哈哈哈
尝试修改了一下,可以试试
21118 什么端口什么的 可以通过路径来转发? 比如 wss://xx/hbbs 转发到内部 127.0.0.1 21118 这样的端口 网页应该有操作空间
这块没搞定。 现在状态是,如果wss链接,就会提示"无法连接注册服务器"了。
通过nginx 反向代理 websocket 实现
location /xxxxx {
proxy_pass http://127.0.0.1:21118;
proxy_set_header Host 127.0.0.1:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
proxy_set_header X-Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
// 主要是下面两个是支持websocket的
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /xxxxx { proxy_pass http://127.0.0.1:21118; proxy_set_header Host 127.0.0.1:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; proxy_set_header X-Host $host:$server_port; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 30s; proxy_read_timeout 86400s; proxy_send_timeout 30s; proxy_http_version 1.1; // 主要是下面两个是支持websocket的 proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
技术有限,基于宝塔反代,反复测试了几次,失败了。
能更详细介绍下么
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:21118;
}
server
{
listen 80;
listen 443;
server_name XXXX.com;
index index.html index.htm index.php default.html default.htm default.php;
location ^~/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
proxy_pass http://websocket;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server 127.0.0.1:21118; } server { listen 80; listen 443; server_name XXXX.com; index index.html index.htm index.php default.html default.htm default.php; location ^~/ { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; if ($request_method = 'OPTIONS') { return 204; } proxy_pass http://websocket; 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_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
当已经存在一个反代(21114)的情况下,这种配置会冲突或者无效。
SSL Websocket 可以使用nginx反向代理处理 建议不要将ws写死 可以通过反代进行代理或者什么都可以的
这里判断当前是https就用wss 否则就用ws