问题
线上部署一功能服务时,部署后使用postman调用接口测试正常,在线上系统中调用时出现接口无法请求通过的现象。
经排查发现,在console中出现了**This request has been blocked; the content must be served over https ;**的错误警告。
引发原因
线上系统为https站点,而部署的服务接口使用的是http请求。在线上系统请求服务接口引发了该错误,https站点无法访问http请求的错误;
HTTPS页面里动态的引入HTTP资源,比如引入一个js文件,会被直接block掉.在HTTPS页面里通过AJAX的方式请求HTTP资源,也会被直接block掉。
解决
方案一
将接口服务改造成使用https 的服务
方案二
采用nginx转发。将该服务接口使用nginx已经配置ssl的监听端口去进行转发操作,只需要配置一项反向代理即可实现。
此处使用了线上的443端口进行转发。
bash
# HTTPS server
#
server {
listen 443 ssl;
server_name myhttps;
root /opte/web;
ssl_certificate /opte/nginx/conf/FKWE.crt;
ssl_certificate_key /opte/nginx/conf/FKWE.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /opte/web;
index index.html index.htm index.php;
}
location ~ \.php$ {
#root /opte/web/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# 证书登陆
location /jit/ {
proxy_pass http://127.0.0.1:8083/jitsss/;
}
}