下面的配置是微信小程序所需的wss的配置,這裏爲了方便,,也爲了不使用端口號,和原項目的配置寫在一塊兒了,所以使用了固定後綴/wss,以做區分,配置的重點就是location /wss 段,其以後的部分是原項目所需的配置.php
upstream websocket { server 127.0.0.1:12121; } server{ listen 443; server_name ___aaa___.com; index index.html index.htm index.php default.html default.htm default.php; root /___aaa___; #include none.conf; #error_page 404 /404.html; include enable-php-pathinfo.conf; ssl on; ssl_certificate /___aaa___.pem; ssl_certificate_key /___aaa___.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; # 用於小程序的 websocket 鏈接 location /wss { proxy_pass http://websocket;#代理到上面的地址去 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location / { # 主項目 } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /___aaa___.log; }
服務端使用 golang的話,若是使用的 github.com/gorilla/websocket ,須要添加如下配置css
var upgrader = websocket.Upgrader{ // 解決跨域問題 CheckOrigin: func(r *http.Request) bool { return true }, }