- 在微服务开发中,服务之间的交互是在所难免的,但是交互过程中,不同域名下导致跨域数据不通,此时nginx作用就很大了,将不同域名反向代理转为同域名服务,就可解决跨域交互问题。 在项目开发中是kkfileView实现文件在线预览时,将kkfileView 部署到服务器之后,应用访问kkfileView 服务打开文件时,显示文件打不开了,解决问题第一步首先确定文件路劲是否正确,在确认文件路劲无误之后开始怀疑跨域问题。
之后就疯狂的配置了一个代理,用来转发 http://192.168.0.110:8012地址,
server {
listen 9508;
server_name localhost;
location / {
proxy_pass http://192.168.0.110:8012;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}`
//文件预览
var url = 'http://127.0.0.1:8080/file/test.txt'; //要预览文件的访问地址
window.open('http://127.0.0.1:9508/onlinePreview?url='+encodeURIComponent(base64Encode(url)));
然后配置再打开文件预览,完美解决,哦 kkfileview是个优秀的开源项目,具体作用观摩官网地址 kkfileview.keking.cn