当前位置:网站首页>Deploying static websites using OSS and CDN on Alibaba cloud international
Deploying static websites using OSS and CDN on Alibaba cloud international
2022-06-10 20:27:00 【87cloud】
As a collection of static files - There is little difference in deployment between static websites and front-end applications . They all come with static files , for example HTML,CSS,JS,JPEG and PNG.
A common method for hosting static websites on alicloud is to use Object storage service (OSS) and Content distribution network (CDN) Of “ Static hosting ” function :
- Managed assets do not require a server
- OSS Store redundant copies of assets across multiple zones within a region ; therefore , Provides high availability at the regional level for the source of assets , Without doing anything else
- CDN For improved delivery , To improve the user experience
- CDN Is a huge global network of interconnected servers , Therefore, it provides high availability for user oriented servers all over the world
- OSS Very cheap
This article 87cloud In this paper, we introduce a simple and reliable way to integrate static websites / How to deploy front-end applications to Alibaba cloud . It provides a good reference for the engineering team of the company who wants to automate the deployment . It should be noted that , Although this can be done with video 、 Audio works with large files , But Alibaba cloud CDN Provides optimized for each use case CDN type ( therefore , By separating these assets and using dedicated CDN type , Can provide a better user experience ).
precondition
Follow this guide , The following conditions need to be met :
- Aliyuncli and ossutil Installed and configured . If you have Docker, The faster option is to use “python hold-all ”, These include
- already installed curl( perhaps , You can use the browser with checking function in the section of checking the title )
- Yes Object storage service (OSS) and Content distribution network (CDN) Deep understanding of
- Linux Basic on the box Linux Skill
Architecture
The following figure shows a simplified flow of what we are going to implement :

So what happened here ? Have source assets (“ Source ”) Your computer will push it to OSS.OSS act as CDN Of “ Source ”, Whenever a copy of an asset is not found in its cache , It will take assets from it ;CDN Accept all requests for static files .
Realization
OSS bucket
Create your OSS Buckets or use existing buckets . I will use CLI To achieve this :
# ossutil mb oss://angry-medusa 1.244258(s) elapsed # ossutil ls oss://angry-medusa Object Number is: 0 0.350505(s) elapsedUpload to OSS
Upload some static files in the current directory to the newly created bucket ; In this example , We uploaded 1 A document – An index .html
# ossutil cp . oss://angry-medusa –rfHere's what it might look like :

Now? , We are OSS Has this file in . Now? , Let's make sure it serves these static assets .
OSS Static page function
Go to the console and bucket , First , take ACL Set to public read:

Now? , Set the default home page as our index .html page :

Let's verify OSS Whether it can provide services for our index .html:

cool , We are OSS Hosted a page on . Simple and easy to use .
add to CDN
although OSS It is good enough for sites with small traffic , but OSS Can't handle a lot of traffic by itself ( That is, a large number of concurrent reads ), And bound to a region . In order to provide a better user experience , You should use CDN, It will provide cached static assets from nodes physically closer to the user , Let alone . The other came from CDN Absorb all incoming reads instead of OSS.
Access control , Set a point to us OSS As the origin CDN domain name , And use “ overseas ” As a region ( China and global options require you get ICP license ):

wait for CDN start-up :

Now? , Let's go through CDN Load our microsite . By clicking on the newly created CDN, We can open the details page , You can configure caching rules in it :

At the time of writing ,CDN The default behavior of is to cache resources 10 second . This is far from optimal , Because it makes CDN Return to too often Origin. Let's set a rule , Cache all resources for a whole month :

Let's write down what we are CDN To obtain the DNS CNAME:

Because we don't actually own the domain , And it is not bound to CDN CNAME, So we will be in curl Sent in “Host” Header to solve this problem :

We can see , Our first request missed the cache . Let's try publishing another :

therefore , The request is actually provided from the cache . Let's see if we update the source html file , Upload again to OSS And query OSS and CDN What's going to happen :

You can see CDN Providing obsolete version of file . Because we actually know when and which files change , So we can make CDN invalid , Then test whether the updated file is satisfied :

Please note that , This time we are curl and invalidation Use full path in . The reason behind this is CDN act , It applies to precise documents / Directory name , to “http://angry-medusa.me.w.kunlungr.com/” Your request will still provide us with outdated documents , Because we didn't invalidate the root directory .
In addition to making it be called “ Pull ” The cache of is invalid , Another technique is to put a newer version of the asset “ push ” To CDN in . The following figure illustrates the main differences between the two technologies :

If a resource is hit by a large number of requests and fails , be CDN In from OSS The time required to get the new version may be invalid , Because all requests for new resources will be forwarded to the origin . Although very robust OSS There are certain concurrent read restrictions , But it may also run out . under these circumstances , The method on the right is more advantageous , Because it guarantees CDN Always in “HIT” Running on the basis of , Assets are actively “ PUSH ” Enter into , Instead of relying on the logic to retrieve it from the origin .
Lock the operating system
up to now , We have actually been able to learn from OSS or CDN Request page . In the real world , This is not desirable , Because malicious users can easily run out OSS Read volume . To solve this problem , Please go to... In the console first OSS, And remove the storage bucket from “ Public read ” Change to “ private ”:


Now turn to CDN Console and change the bucket settings :

If you have not previously authorized CDN Use OSS, Please do this in the following way :

You will be directed to access the enable page :

Please note that , This is a general access rule ; You may want to go through RAM The console more finely restricts access . After reloading the form , It allows CDN visit OSS:

Let's verify , We no longer have direct access to OSS, but CDN from Origin There is no problem acquiring assets :

this is it ; We are now stopping the right OSS Direct access , And allow from CDN Visit it .
Conclusion
As you can see , Deploy front-end applications and get OSS and CDN The significant advantage of is quite straightforward :
# copy your assets over: # ossutil cp . oss://angry-medusa –rf # invalidate the cache through pull: # aliyuncli cdn RefreshObjectCaches --ObjectType Directory --ObjectPath http://angry-medusa.me/ # invalidate through push # aliyuncli cdn PushObjectCache --ObjectPath http://angry-medusa.me/ --ObjectTyp e Directory # partyThis document describes the use of OSS Static website hosting function and CDN Pairing is a simple way to deploy front-end applications to alicloud . This approach enables teams to quickly start deploying their front-end applications , Without going through setup and maintenance Web The pain of server infrastructure .
边栏推荐
- 软件定义边界(SDP)
- [observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation
- Redis cluster form - sentry mode cluster and high availability mode cluster - redis learning notes 003
- Handwritten code bind
- 4.35V锂电充电IC
- Mysql database foundation
- 8.4v双节锂电池专业充电ic(FS4062A)
- After the college entrance examination, VR panoramic tour will show you the beautiful scenery of the scenic spot
- 【Educational Codeforces Round 120 (Rated for Div. 2)】C. Set or Decrease
- Bit operation topic
猜你喜欢

Fs2117 boost IC output 5v2.4a synchronous rectification

用 Plotly 绘制了几张精湛的图表,美翻了!!

软件定义边界(SDP)

Zabbix_ Principle Architecture - installation and deployment - Custom monitoring

JD released ted-q, a large-scale and distributed quantum machine learning platform based on tensor network acceleration

国庆期间给大家推荐一个可能会成为2019最佳的CRUD工具

8.4v双节锂电池专业充电ic(FS4062A)

江波龙 FORESEE XP2000 PCIe 4.0 SSD 多重加密功能,锁定数据安全

PDU session flow

历时2年442位作者132个机构!Google发布语言模型评价新基准BIG-bench,204个任务全面评价语言模型能力,附论文
随机推荐
Recording a super Oolong mental retardation bug may help people like me eat for free
户外太阳能野营灯移动电源方案
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
Soft deletion of data - when? How to realize it?
Key points of lldp protocol preparation
Trilogy to solve the problem of playing chess first and then
After the college entrance examination, VR panoramic tour will show you the beautiful scenery of the scenic spot
融入机器学习,让Chrome浏览器更“懂”你
如何使用物联网低代码平台进行工作表管理?
老程序员说:别再直译这大千世界了,开发人员应该回归程序设计
How to realize face verification quickly and accurately?
Looking for a room in the graduation season of college students, VR panoramic viewing helps you screen Online
身份识别与访问管理(IAM)
nodejs: 官方文档3 dgram Stream
【录入课本latex记录】
FS2117升压IC输出5V2.4A同步整流
Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
监控易打造“准生态”格局,赋能信创“平替”
批量检测不同url的指定端口(py脚本)
零信任架构