|
|
10 сар өмнө | |
|---|---|---|
| .cursor | 11 сар өмнө | |
| external | 10 сар өмнө | |
| logger | 10 сар өмнө | |
| wsClient | 10 сар өмнө | |
| .env.example | 10 сар өмнө | |
| .gitignore | 11 сар өмнө | |
| README.md | 10 сар өмнө | |
| config.env.example | 11 сар өмнө | |
| go.mod | 11 сар өмнө | |
| go.sum | 11 сар өмнө | |
| main.go | 10 сар өмнө |
/room?room=<房间名> 动态创建/加入房间,彼此隔离。创建Nginx WebSocket 配置文件。参考测试环境的 nginx conf 文件 -- chat.shop.huaml.com.conf
server {
listen 443 ssl;
server_name chat.shop.huaml.com;
ssl_certificate /usr/local/nginx/cert/webSocket/chat.shop.huaml.com.pem;
ssl_certificate_key /usr/local/nginx/cert/webSocket/chat.shop.huaml.com.key;
location / {
proxy_pass http://127.0.0.1:8080;
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_read_timeout 120s; # 读超时(客户端多久没发消息就断开)
}
}
摘取代码,执行:go build main.go
把生成的 main 文件放到线上,并配置好 .env 文件
LOG_MODE=color
LOG_LEVEL=0
REDIS_ADDR=118.178.193.23:6379
REDIS_PASSWORD=byt6gc1w0aed2q7h
REDIS_DB=0
SERVER_ADDR=:8080
HUA_ZHANG_GUI_URL=https://api.shop.huahb.cn
HUA_HUI_BAO_URL=https://api.shop.zhiguanhua.cn
要把对应配置项改为线上的
后台运行(简单方法)
使用 nohup 或 &:
nohup ./main > ./message_server.log 2>&1 &
查看进程:
ps -ef | grep main