目的
底层服务返回的ws地址代理成wss的, 但是我们不知道底层服务返回的地址ip port所以 通过拼接的方式来通过url信息中获取到ws地址信息,进行动态代理
nginxconf_3">nginx.conf
server {listen 11081 ssl;server_name localhost11081;rewrite ^/old-url$ /new-url permanent;add_header Access-Control-Allow-Origin '*'; add_header Access-Control-Allow-Credentials "true";add_header Access-Control-Allow-Methods 'GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACES';add_header Access-Control-Allow-Headers 'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,XRequested-With';ssl_certificate /home/zhkj/ssl/certificate.crt;ssl_certificate_key /home/zhkj/ssl/private.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location /_proxy/ {# 通过正则截取路由中的 sub urlif ($request_uri ~* "/_proxy/(.*)") {set $proxy_url $1;}proxy_pass http://$proxy_url;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_read_timeout 3600s;proxy_send_timeout 3600s;}
}
示例
ws
ws请求地址
wss://192.168.201.55:11081/_proxy/192.168.150.242:8082/giga/ch3/stream1
192.168.150.242:8082/giga/ch3/stream1是被代理的地址
https
https请求地址
https://192.168.201.55:11081/_proxy/192.168.0.132:7000/VideoPlatfrom/test/