Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于CDN #69

Open
xxxxxccc opened this issue Apr 17, 2018 · 4 comments
Open

关于CDN #69

xxxxxccc opened this issue Apr 17, 2018 · 4 comments

Comments

@xxxxxccc
Copy link

elemeFE的同学,您好,我这里有一个问题想请教:
整站静态化后,整个文件包放入CDN,链接该如何配置?如果过nginx,那么相当于进一遍服务器,再跳入CDN,就等于在服务器绕了一圈,没有达到最优速度;如果不配置,那链接就不友好;求赐教,万分感谢了!

@Lellansin
Copy link
Contributor

Nginx 301?

@xxxxxccc
Copy link
Author

重定向还是先进到服务器,再进入CDN,失去了CDN第一跳最快的优势

@pwang2
Copy link

pwang2 commented Apr 20, 2018

如果友不友好指的是CORS和域名, 那么可以直接设置DNS CNAME指向CDN。 然后设置CORS header。 参见:

dig +cmd +multiline +all +answer abs.twimg.com

; <<>> DiG 9.10.6 <<>> +cmd +multiline +all +answer abs.twimg.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31109
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;abs.twimg.com.         IN A

;; ANSWER SECTION:
abs.twimg.com.          147 IN CNAME cs196.wac.edgecastcdn.net.
cs196.wac.edgecastcdn.net. 3331 IN CNAME cs2-wac.apr-8315.edgecastdns.net.
cs2-wac.apr-8315.edgecastdns.net. 100 IN CNAME cs2-wac-us.8315.ecdns.net.
cs2-wac-us.8315.ecdns.net. 100 IN CNAME cs45.wac.edgecastcdn.net.
cs45.wac.edgecastcdn.net. 3331 IN A 72.21.91.70

@guibwl
Copy link

guibwl commented Aug 27, 2019

我也遇到过这个问题,提供个解决方案:

1,搭建独立静态资源服务器,供CDN回源:
单独弄台服务器用来存放静态资源,申请独立的域名或者域名后面加个唯一路径‘www.domain.com/static’,cdn回源指向这个地址。在发布流水线中将js、图片等静态资源推到这台服务器上去。

2,前端静态资源直接访问CDN:
前端工程里所有静态资源打包都加上hash,publicPath 直接配置 CDN 对应的地址。

以上需要注意的:
CDN回源的服务器不区分测试和生产环境,所有上传文件都要加上hash,刷新CDN缓存必须谨慎;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants