目录
起因
在有些音视频的前端应用里,要求必须使用https的web架设,如图
如果你不想把你的web架设成https,你可能需要在你的浏览器里处理:
TypeError: Cannot read property 'getUserMedia' of undefined - 养猪至富 - 博客园
但是在https网站内发送http的ajax请求报错
可以看到是在https://127.0.0.1 请求http://10.60.2.185:2580/GSoapWebserviceSDK/service/service.php便失败。并且报错
Mixed Content: The page at ‘https://127.0.0.1/’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ‘http://10.60.2.185:2580/GSoapWebserviceSDK/service/service.php’. This request has been blocked; the content must be served over HTTPS.
大致意思就是https网站内不可以发送http请求,并且http请求直接被拦截并不发送到后台服务器。
解决方案如下几种:
修改https 为 http协议,大部分不可取
修改后台的http服务器为https协议,并修改前端代码
修改前端代码请求地址为nginx地址,使用当前https服务器对应的nginx转发前端https请求发送到后台http服务器,从而不用修改http服务器。
如第三种方案
网上的例子为:
127.0.0.1 kafka1
1
nginx配置如下:
# 配置后台服务器地址
upstream kafka1{
ip_hash;
server 127.0.0.1:8080;
}
server {
listen 443 ssl;
server_name kafka1;
ssl_certificate shfqcert.cer;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# 转发到后台服务器
proxy_pass http://kafka1;
proxy_buffer_size 8k;
proxy_buffers 64 32k;
}
}
我的,直接加一个:
location /php-server{
proxy_hide_header X-Frame-Options;
add_header X-Frame-Options ALLOWALL;
proxy_pass http://10.60.2.185:2580/GSoapWebserviceSDK/service/service.php;# 后端地址
}
前端的修改一下:
然后前端可以发送请求之后,后台如果没有做跨域处理的话需要修改响应的请求头。
服务端需要设置响应头Access-Control-Allow-Origin为* 或者当前访问后端服务器的地址
如当前我这里是这个访问地址是https://localhost/
如 SpringMVC的 @CrossOrigin("https://localhost"),每个语言的都不尽相同,但都是响应头添加Access-Control-Allow-Origin罢了
实践
/docker/nginx/jitsi/
/etc/nginx/conf.d/jitsi.conf
参考
https://blog.csdn.net/u013076044/article/details/84261762
TypeError: Cannot read property 'getUserMedia' of undefined - 养猪至富 - 博客园