企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#### nginx 配置wss 原理利用反向代理实现,现在的项目基本上都是https的,如果用ws就会报错。只有提升为wss来使用。 ~~~ ## wss需要设置的 map $http_upgrade $conn_upgrade { default upgrade; '' close; } ## wss需要设置的 server { listen 443 ssl; ssl_certificate D: /phpstudy/Extensions / Nginx1 .15 .11 / conf / ssl / admin.cn.pem; ssl_certificate_key D: /phpstudy/Extensions / Nginx1 .15 .11 / conf / ssl / admin.cn.key; ssl_session_timeout 5 m; 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; server_name admin.cn; root "D:/phpstudy/WWW/admin.cn/public"; location / { index index.php index.html error / index.html; error_page 400 / error / 400. html; error_page 403 / error / 403. html; error_page 404 / error / 404. html; error_page 500 / error / 500. html; error_page 501 / error / 501. html; error_page 502 / error / 502. html; error_page 503 / error / 503. html; error_page 504 / error / 504. html; error_page 505 / error / 505. html; error_page 506 / error / 506. html; error_page 507 / error / 507. html; error_page 509 / error / 509. html; error_page 510 / error / 510. html; include D: /phpstudy/WWW / admin.cn / public / nginx.htaccess; autoindex off; } ##访问域名wss: //admin.cn/wss 即可 location / wss { proxy_pass http: //127.0.0.1:8080/sync;##代理到上面的ip proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $conn_upgrade; } ##访问域名wss: //admin.cn/wss 即可 location~\.php(.*) $ { fastcgi_pass 127.0 .0 .1: 9001; fastcgi_index index.php; fastcgi_split_path_info ^ (( ? U). + \.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } ~~~ 其中主要代码是 ~~~ map $http_upgrade $conn_upgrade { default upgrade; '' close; } // 反向代理设置地址 location / wss { proxy_pass http: //127.0.0.1:8080/sync;##代理到上面的ip proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $conn_upgrade; } ~~~ #### 设置后重启nginx后即可,访问地址如下,亲测有效 > wss: //admin.cn/wss