把官网的推送服务切换到了websocket了
By
lincanbin
at 2017-12-26 • 1人收藏 • 10311人看过

顺带把环境切换到了PHP 7.1。
一键WebSocket部署脚本。
65 个回复 | 最后更新于 2017-12-28

根据自己实际调整Nginx的最大超时时间,我因为用了WSS,所以是用Nginx proxy实现的websocket加密传输。
根据自己情况修改keepalive_timeout等各种timeout。
爆栈网有相关文章:https://stackoverflow.com/questions/10550558/nginx-tcp-websockets-timeout-keepalive-config
proxy_connect_timeout 7d; proxy_send_timeout 7d; proxy_read_timeout 7d;
浏览器会发送ping pong心跳包,所以这个socket长一些也没事,我设置了7天。
登录后方可回帖


Memcache轮询。
粤公网安备 44030602003677号
参考的config.php
define('WebSocketFrontendPort', '443'); define('WebSocketBackendPort', '2000');参考的Nginx配置:
server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2; server_name www.94cb.com 94cb.com m.94cb.com api.94cb.com cdn.94cb.com; ssl on; ssl_certificate_key /etc/letsencrypt/live/www.94cb.com/privkey.pem; ssl_certificate /etc/letsencrypt/live/www.94cb.com/fullchain.pem; set $redirect_to_https 1; if ($host = 'cdn.94cb.com') { set $redirect_to_https 0; } if ($scheme = https) { set $redirect_to_https 0; } if ($redirect_to_https = 1) { rewrite ^(.*) https://$host$1 permanent; } root /www/web/carbon/public_html; index index.html index.php index.htm; include /www/web/carbon/public_html/nginx.conf; # 开启SSL的WebSocket的配置主要是这部分,如果没使用SSL可以不需要配置这个 location /push { # redirect all HTTP traffic to localhost:2000 proxy_pass http://127.0.0.1:2000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # WebSocket support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # WebSocket timeout proxy_connect_timeout 7d; proxy_send_timeout 7d; proxy_read_timeout 7d; } location ~ \.php(.*)$ { fastcgi_pass unix:/tmp/php-71-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name; fastcgi_param PATH_INFO $2; include fcgi.conf; } #图片缓存7天 location ~.*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 7d; } #js css缓存1天 location ~.*\.(js|css|html)$ { expires 24h; } access_log /www/web_logs/94cb.com_access.log wwwlogs; error_log /www/web_logs/94cb.com_error.log; }