当前位置:网站首页>Some practical strategies for accessing CDN

Some practical strategies for accessing CDN

2020-12-07 19:16:46 six million one hundred and ten thousand five hundred and twent

Preface

When your website or APP The number of visits is increasing , The user experience continues to decline , When the server performance is seriously insufficient , Select access CDN It's what you have to do in most situations , When you're in a lot of CDN One of the manufacturers finally chose ( I don't know how to choose , You can choose Tencent cloud with your eyes closed CDN), When configuring , Don't simply think that everything is OK after the configuration according to the introduction document . Many cases prove that , Access CDN It's just a small step , All sorts of problems that come up later , It's going to drive you crazy . Let's talk about how to use it well CDN, Let it work at its best . The following is about CDN matter , With Tencent cloud CDN As a case study , For reference only .

Step1. Resource Division

If you haven't divided the resources before , A preliminary analysis is suggested , Determine resource attribute classification , For example, static small files (css、js、jpg etc. )、 Video file (mp4、avi etc. )、 Program installation package (apk etc. )、 Dynamic resources (api、php etc. ) etc. , Using different domain names to carry . Don't bother here , All resources are hosted by one domain name , Risk is bigger , It's not good for performance optimization and project management . After the domain name split , Access CDN Before , You may also need to prepare a certificate , If conditions permit , It will be much easier to prepare a pan domain name certificate . Certificate application and purchase can refer to :https://cloud.tencent.com/document/product/400/7995

Step2. Function sorting

Some access resources , You may need some additional configuration , Like the anti-theft chain 、 special Header To configure 、 Remote Authentication 、302 Jump, etc , In the configuration CDN Before , Sort out , According to the above domain name planning , One by one , recorded . These functions need to be prefixed to CDN To complete , Missing these , It will bring some unnecessary trouble .

Step3. Source station preparation

The origin is CDN Where to get resources when the cache fails or there are no files , During the convenient period , You can put the current web Server as CDN Source station of , Pay attention to the scale of business growth , Expand the capacity appropriately . Besides , The exit of the origin station should have more ISP exit , Reduce the potential for CDN Poor performance back to source , in addition , It is recommended to set up primary source and standby source , On the one hand, data backup and disaster recovery requirements , On the other hand , Reduce the number of failures due to return to the primary source CDN The visit to fail .

If the site needs to store a lot of files , It costs a lot to build a file server by yourself , Cloud storage can be used as the origin . Object storage (Cloud Object Storage,COS) It is a distributed storage service provided by Tencent cloud to store massive files , Users can store and view data at any time through the network . Tencent cloud COS So that all users can use, with high scalability 、 Low cost 、 Reliable and secure data storage services .CDN+COS It is a high-quality solution for file storage and distribution .

Step4. Configuration practice

Specific to configuration , For beginners, you can refer to the guidance document , For example, Tencent cloud CDN《 Configure from scratch CDN》. We will not repeat here , In this section, we focus on several best practice parameter configurations .

First of all, in the preferred access domain name configuration , It should be noted that , Need to sort out the domain name according to the function , Choose the right business type . It's about your domain name being assigned to the right acceleration platform , Generally speaking CDN Manufacturers are targeting small files 、 download 、 Streaming media on demand will have different platforms and optimization parameters . If the choice is wrong , Although it will not lead to business access failure , But it will have a certain impact on the quality of access .

Choose the right business type

If it's a static small file (css、js、jpg etc. ), Please select static acceleration ; A large file , Download distribution domain name , Choose download acceleration ; Video related selection streaming media on demand acceleration . Come here , You will understand , Why? Step1 It is suggested to divide resources .

Continue configuration , It's about cache configuration , This is optional , Later can also be modified in the domain name management , It is suggested to plan ahead of time .

Cache configuration

If it's big files and on demand , Suggest opening Slice back to the source , There is no need for static small files , Fragment back to source can greatly improve the hit rate and distribution effect of large files . in addition , If business URL Carried in querystring Equal parameter , It has nothing to do with the contents of the file and the parameters change frequently , That is, the parameter changes , It doesn't mean the document has changed , It is strongly recommended to turn on Filter parameters , This greatly improves the cache hit ratio , Improve access quality . as for , Cache time , Here, according to the business requirements , File update is not the case with the same name , It can be set longer . in addition , We need to pay attention to , Files that need to be cached , The source station returned cache-control header It must not be no-cache 、 no-store or private, At this time, the platform strategy is not cached . You can refer to :https://cloud.tencent.com/document/product/228/41534

in addition , Through the domain name management interface , In the back to source configuration project , You can also set :

Go back to the source and follow - After opening , For the return of the origin station 301、302 Conduct Follow Get resource cache .

Return to source timeout — You can adjust the timeout for back to source connections and reads , In some cases, the source station responds slowly , After turning up , It can greatly alleviate the failure of returning to the source .

The next recommended option is to configure the hot standby source station . Note all the optimization options mentioned below , After adding the domain name , Enter the domain name management page for operation .

Configure hot standby source

The significance of the existence of backup source , When CDN Need to go back to the source , When the connection to the master station fails or the master station fails , There will be many retries though , However, the standby source will be enabled immediately when the primary source fails , Will not cause this request to fail , No sense to users .

Fourth , At present HTTPS Is an essential function , It is suggested that after configuring the domain name , hold HTTP2 as well as OCSP Open it up :

•HTTP2.0— After opening , Support http2, Suggest WEB The page opens , Optimize page speed . At present, mainstream browsers already support , It's also a mainstream trend .

OCSP binding —OCSP(Online Certificate Status Protocol, Online Certificate Status Protocol ) Is used to verify the validity of the certificate online query service , Generally, the certificate belongs to CA Provide . Some clients will be in TLS In the handshake phase, when further negotiations are made , Real-time query OCSP Interface , And block the follow-up process before getting the result .OCSP The nature of the query is complete HTTP request - Respond to , In between DNS Inquire about 、 establish TCP、 Server side processing and other links may take a long time , Leading to the eventual establishment of TLS The connection time becomes longer . Recommended Opening , After opening , Great optimization TLS Handshake time . in addition , For some low-end or free certificates issued ( such as :Let's Encrypt), When the certificate is assigned ocsp The address is overseas , There is no acceleration on the Mainland , Can greatly alleviate apple System access failure —— certificate ocsp Address check :openssl x509 -noout -ocsp_uri -in xx.pem Or open it in the browser :

certificate ocsp Address

If this ocsp Domain name resolution is all overseas , It could be a wall at any time , Lead to ios Can't open up resources , because IOS The system's certificate verification policy depends on this method . Other systems rarely encounter , They use another certificate checking mechanism .

The last option I would like to recommend to you is Intelligent compression , This static resource , Be sure to open , Reduce traffic , Speed up transmission . The benefits of compression are no longer to be said .

Intelligent compression

Step5. Switch resolution

The above work is done , After the configuration of the domain name is completed ,CDN It will assign a CNAME Here's the address , Need you to speed up the domain name DNS The analysis points to this CNAME Address , You can really use CDN service . You can refer to CNAME To configure 《 guide 》. The advice here is , If conditions permit , And online business flow is running , Don't ALL IN Switch , Take the strategy of regional gray level . Cut one or two areas first CDN On , Let's see if there are any problems with the service or the feedback from users . The difficulty here is that the authoritative resolution server of domain name has the function of sub line resolution . The benefits of having multi line resolution are also , You can use more than one at the same time CDN Manufacturers come to serve , Distribute traffic by Region , When one of them breaks down , You can switch to others CDN Fast recovery . If you want to experience the multi line parsing function , recommend DNSPOD Resolution service :https://cloud.tencent.com/product/cns

Step6. Data analysis

When services are in CDN When it's up and running , Don't go away , You need to focus on traffic 、 Bandwidth and hit rate , In order to make timely adjustments , Give advice or improvement to CDN manufacturer , Get the best return . Through the statistical analysis function of the console , You can get the indicators in real time . And configure some necessary monitoring according to the data . Such as attention TOP User access area , To compare the quality of visits to these areas , See if it's local coverage, etc . Data analysis and utilization is a long-term thing .

Last

The above is for access CDN Some practical optimization strategies for , I hope it can be helpful in your production practice . in addition , If you are using Tencent cloud CDN There are also some deep usage or suggestions on the aspect , Welcome to contact us .

Original statement , This article is authorized by the author + Community publication , Unauthorized , Shall not be reproduced .

If there is any infringement , Please contact the yunjia_community@tencent.com Delete .

版权声明
本文为[six million one hundred and ten thousand five hundred and twent]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/11/20201112182545416y.html