背景:做一项目,要从http协议升级为https协议,导致视频播放不了,控制台报错,具体请求视频使用的是http协议,导致阻塞。
当时有两种方法,
第一:(比较low)
1)FireFox解决方法:
打开新标签页,在地址栏输入about:config,进入配置页面。
搜索 security.mixed_content.block_active_content,将true改为false。
2)Chrome解决方法:
右键点击Chrome快捷方式,在快捷方式 “目标”后加参数:
–allow-running-insecure-content
第二:利用nginx将https协议转换成http(视频请求走的是http)
在nginx中添加如下配置,端口根据需要更改,证书生成请自行百度(可使用OpenSSL)。
upstream images {
ip_hash;
server localhost:8080;
}
# HTTPS server
server {
listen 10080 ssl;
server_name localhost;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://images;
}
}
另附上几个nginx配置。
1,同时支持http和https请求(实际将所有的请求通过反向代理成http请求)
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream images {
ip_hash;
server localhost:8080;
}
# HTTPS server
server {
listen 8080;
listen 443 ssl;
server_name localhost;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://images;
}
}
}
2、https请求支持多端口
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream images {
ip_hash;
server localhost:8080;
}
# HTTPS server
server {
listen 8080;
listen 443;
server_name localhost;
ssl on;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://images;
}
}
}
ps:在windows电脑,当ssl.crt和ssl.key写绝对路径时,启动nginx会报错,所以直接将此配置放入conf文件夹下。