-
-
Notifications
You must be signed in to change notification settings - Fork 78
GGSWebsocketConfig
oyx319 edited this page Sep 3, 2024
·
2 revisions
ggs服务新增网页版websocket访问的功能, 需要ggs在调用worker节点时,默认使用wss访问worker节点。
通过域名+端口调用ggs服务
环境 | ggs服务 | ggs节点内外网IP | 域名 | WebSocket端口 |
---|---|---|---|---|
生产环境 | ControlServer | 172.30.0.14 | ggs-wss.keepwork.com | 9000 |
生产环境 | WorkerServer | 172.30.0.14 | ggs-wss.keepwork.com | 9001 |
生产环境 | WorkerServer | 172.16.0.5 | ggs-wss.keepwork.com | 9002 |
生产环境 | WorkerServer | 172.16.0.16 | ggs-wss.keepwork.com | 9003 |
新增ggs.conf配置
## GGS control节点
server {
listen 9000 ssl;
server_name ggs-wss.keepwork.com;
ssl_certificate /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.pem;
ssl_certificate_key /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.key;
access_log /var/log/nginx/access/ggs-wss_keepwork_com.log;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://172.30.0.14:9000;
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;
# 添加 CORS 头部支持跨域
add_header 'Access-Control-Allow-Origin' '*'; # 允许任何来源
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# 处理预检请求
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
## 当GGS worker节点与Controller节点不在同一台机器上时,需要配置两个nginx配置文件,域名均为ggs-wss.keepwork.com,端口不一样,可以设置为9001,、9002等等
## GGS worker节点172.30.0.14
server {
listen 9001 ssl;
server_name ggs-wss.keepwork.com;
ssl_certificate /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.pem;
ssl_certificate_key /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.key;
access_log /var/log/nginx/access/ggs-wss1_keepwork_com.log;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://172.30.0.14:9000;
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;
# 添加 CORS 头部支持跨域
add_header 'Access-Control-Allow-Origin' '*'; # 允许任何来源
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# 处理预检请求
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
## GGS worker节点172.16.0.5
server {
listen 9002 ssl;
server_name ggs-wss.keepwork.com;
ssl_certificate /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.pem;
ssl_certificate_key /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.key;
access_log /var/log/nginx/access/ggs-wss2_keepwork_com.log;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://172.16.0.5:9000;
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;
# 添加 CORS 头部支持跨域
add_header 'Access-Control-Allow-Origin' '*'; # 允许任何来源
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# 处理预检请求
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
## GGS worker节点172.16.0.16
server {
listen 9003 ssl;
server_name ggs-wss.keepwork.com;
ssl_certificate /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.pem;
ssl_certificate_key /etc/nginx/ssl/keepwork_com/nginx/keepwork.com.key;
access_log /var/log/nginx/access/ggs-wss3_keepwork_com.log;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://172.16.0.16:9000;
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;
# 添加 CORS 头部支持跨域
add_header 'Access-Control-Allow-Origin' '*'; # 允许任何来源
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# 处理预检请求
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
}
}
来源 | 协议端口 | 策略 | 备注 |
---|---|---|---|
0.0.0.0/0 | TCP:9000,9001,9002,9003 | 允许 | ggs的websocket端口 |
在每个ggs WorkerServer节点上修改该节点websocket的访问地址和端口(各个worker节点的端口据上面nginx配置的9001~9003填入)
新增两行配置:
websocketIp="ggs-wss.keepwork.com"
websocketPort=9001
<!-- GGS 后端配置 -->
<GeneralGameServer>
<!--服务器配置
threadCount 工作线程数量 可设置cpu数
threadMaxClientCount 每个线程维护客户端数量 500
listenIp 服务器监听的IP
listenPort 服务器监听的端口
isControlServer 是否为控制节点
isWorkerServer 是否为工作节点
maxClientCount 可接受的最大客户端数 建议: threadCount * threadMaxClientCount
maxWorldCount 可接受的最大世界数
-->
<Server
threadCount=8
threadMaxClientCount=500
listenIp="0.0.0.0"
websocketIp="ggs-wss.keepwork.com"
websocketPort=9001
isControlServer=true
isWorkerServer=true
maxClientCount=8000
maxWorldCount=200>
.
.
.
.
省略
通过下面CI流水线发布
开发环境CI: https://ci.kp-para.cn/job/ggs/
生产环境CI: https://cd-online.keepwork.com/job/ggs/
线上环境, 打开游览器,并登录
https://webparacraft.keepwork.com/
在世界中,打开命令行输入:
/ggs connect -serverIp=ggs-wss.keepwork.com
Download Paracraft | ParacraftSDK | copyright by tatfook 2016 | upload image