微信小程序API需要https,websocket需要wss
首先配置好域名及站点
Let's Encrypt配置好ssl
workerman配置websocket端口4433
nginx配置文件添加
server {
listen 80;
server_name wss.aaa.com;
root /var/www/aaa;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
upstream wxappwss{
#websocket后台实际地址
server localhost:4433;
}
server {
listen 443;
server_name wss.aaa.com;
ssl on;
index index.html index.php;
ssl_certificate "/etc/letsencrypt/live/wss.aaa.com/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/wss.aaa.com/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://wxappwss;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
最后 service nginx reload 即可
在线wss测试网址http://www.blue-zero.com/WebSocket/
网友评论