今天做项目,使用thres.js加载STL3D模型的时候,提示资源跨域,无法渲染。然后百度各种搜,vue的 proxyTable 也使用上了,都没有效果
后来使用nginx直接配置反向代理解决。例如
我们的网站域名是:https://www.blog.liuyanla.com
我们资源的域名是:http://www.abc.com/file/demo.stl
找到nginx的配置文件,我的服务器路径是:/usr/local/nginx/conf.nginx.conf

然后下面是重点:
server {
listen 80; server_name localhost;
location / {
root /hibeauty/dist;
try_files $uri $uri/ /index.html;
index index.html;
}
#重点部分
location /file {
proxy_pass http://www.abc.com;
}
这个时候当你访问 https://www.blog.liuyanla.com /file/demo.stl 的时候就用自动访问 http://www.abc.com/file/demo.stl 文件,跨域问题解决,哈哈
以上就是我遇到的使用nginx代理跨域问题的解决办法。
近期评论