Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

AWS cloud product CloudFront + ELB + EC2 + S3 to build a virtual master mobile + static separation site

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. Architecture Diagram

We want to implement the architect, an EC2 two virtual hosts, through an ELB, a CloudFront to achieve static and dynamic separation, and to achieve different domain names to access different websites, and enable HTTPS.

Second, implement step 2.1, EC2 configuration

Install the nginx service on the EC2, create the website files for the two virtual hosts, and the virtual host configuration files, as follows:

The path to the website is as follows, and the picture is referenced by the tag on the home page.

├── test1 │ ├── images1 │ │ ├── 1.jpg │ │ └── 2.jpg │ └── index.html └── test2 ├── images2 │ ├── 1.jpg │ └── 2.jpg └── index.html

The nginx configuration files for the two virtual hosts are as follows:

Server {listen 80; server_name test1.wzlinux.com; root / usr/share/nginx/test1; location / {} location ~. *\. (gif | jpg | jpeg | png | swf) ${expires 30d;} location ~. *\. (js | css)? ${expires 12h }} server {listen 80; server_name test2.wzlinux.com; root / usr/share/nginx/test2; location / {}}

When the domain name is resolved to EC2, there is no problem with verification. After testing, the security group can only be accessed by the traffic of the security group to which ELB belongs. In fact, HTTPS can also be configured here, which is omitted here.

2.2, ELB setting 2.2.1, create target group

After creating the target group, remember to add the registration instance, which is our EC2.

2.2.2. Create a load balancer

We can add HTTPS snooping (optional) so that we can encrypt access and set various rules, which we don't need here, just add.

Then resolve the domain name to our ELB, and use HTTP and HTTPS to access our two virtual hosts, both of which can display their respective pages normally. For certificate applications, we can use AWS's ACM service.

2.3, S3 Settin

You can create it by default. Because our origin server has a directory for calling images, we also create two directories for two virtual hosts to call respectively, and put the images in the directory.

2.4.The CloudFront allocation

The general architecture diagram is as follows:

2.4.1. Create an assignment

We choose WEB distribution.

We default to the source cache settings.

Assign settings to write the domain name of our own virtual host and use the certificate we applied for in ACM.

2.4.2. Add S3 source

Just now we have an accelerated source site, because we have transferred static images to S3, so we need to add a S3 as the source of CDN.

2.4.3, create behavior

We create an action that will use S3 as the source and other paths continue to access ELB when the directory requested by the user is images1 or images2.

Then point our domain name resolution CNAME to the domain name of CDN, and then access the effect. Whether the image is loaded with S3 content can also be checked through the log. After we add Host to the whitelist header, Host is passed to EC2, which realizes the function of virtual host.

Welcome to scan the code and follow us for more information.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report