当前位置:网站首页>Cross-domain network resource file download
Cross-domain network resource file download
2022-08-01 10:02:00 【ten nine eight seven】
Question
Under normal circumstances, it is impossible to send cross-domain requests to download files.Take downloading Yuque as an example: you can see that if you directly access the download address, a cross-domain error will be reported
Resolve
At this time, we can forward the request through the nginx configuration proxy to complete the download:
location ^~ /yuque/ {proxy_pass https://app.nlark.com/yuque-desktop/;}Description: When we send a request like
/yuque/locally, nginx will forward the request (Note:/must be added at the end, otherwise it is a proxy request, addThen the forwarding request), will forward/yuque/to the followinghttps://app.nlark.com/yuque-desktop/
Then we rewrite the download request:
var xhr = new XMLHttpRequest();xhr.open("GET", "/yuque/1.1.4/Yuque-1.1.4.exe", true);xhr.send();This time, we will not directly access the Yuque download address, but visit our local address, and then nginx will forward our request and forward
/yuque/tohttps://app.nlark.com/yuque-desktop/, then the forwarded request becomeshttps://app.nlark.com/yuque-desktop/1.1.4/Yuque-1.1.4.exe.Since we do not directly request the download address, but the local address of the request, and forward the request through the proxy of nginx, there is naturally no cross-domain problem (if you don't understand, you can read the article I wrote about nginx reverse proxy before)
Afterword
Because nginx does not pass reverse proxy but forward proxy requests, in this process, the resource passes through the nginx server once, and then nginx sends the resource to the requester, so this process needs to consume the location of nginxserver traffic.
边栏推荐
- Is the real database data of TiDB stored in kv and pd?
- 编码解码(btoa、encodeURIComponent、encodeURI、escape)
- 招聘随想2022
- CTFshow,命令执行:web31
- 微信公众号授权登录后报redirect_uri参数错误的问题
- ASP.NET Core 6 Framework Revealing Instance Demonstration [30]: Develop REST API with Routing
- MacOS下postgresql(pgsql)数据库密码为什么不需要填写或可以乱填写
- 已解决(pip安装库报错)Consider using the-- user option or check the permissions.
- STM32个人笔记-嵌入式C语言优化
- 【Untitled】
猜你喜欢
随机推荐
记一次 .NET 某智慧物流WCS系统CPU爆高分析
50.【动态二维数组的运用】
阿里腾讯面试一二
STM32 Personal Notes - Embedded C Language Optimization
笔记。。。。
sql server, FULL mode, dbcc shrinkfile(2,1) can not shrink the transaction log, or the original size, why?
2022年中盘点 | 产品打底,科技背书,广汽集团阔步向前
浏览器快捷键大全
BGP综合实验
rpm and yum
Change Servlet project to SSM project
Enterprise WeChat group: robot timing reminder function database configuration
微服务:事务管理
ClickHouse入门介绍与其特性
使用ESP32驱动QMA7981读取三轴加速度(带例程)
笔记。。。。
Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"
IntellJ IDEA如何显示换行符(line endings)
DBPack SQL Tracing 功能及数据加密功能详解
RK3399平台开发系列讲解(内核入门篇)1.52、printk函数分析 - 其函数调用时候会关闭中断








