AWS cloud offering CloudFront + ELB + EC2 + S3 construct virtual host static and dynamic separation site

First, the architecture diagram

We want to achieve an architect, a two EC2 virtual hosts, through a ELB, a CloudFront achieve static and dynamic separation, and achieve different different domain name visit the Web site, and enable HTTPS.

AWS cloud offering CloudFront + ELB + EC2 + S3 construct virtual host static and dynamic separation site

Second, the implementation steps

2.1, EC2 configuration

Install nginx on top of EC2 service, create two virtual host website files, and virtual host configuration file, are as follows:
site path follows Home inside the picture by reference label.

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

Two virtual hosts corresponding nginx configuration file as follows:

     server {
        listen       80;
        server_name  test1.wzlinux.com;
        root         /usr/share/nginx/test1;

        location / {
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
    }

    server {
        listen       80;
        server_name  test2.wzlinux.com;
        root         /usr/share/nginx/test2;

        location / {
        }
    }

DNS to EC2, verify that there is no problem, after a good test, security groups can be changed to only allow traffic ELB where security group visit, in fact, here you can configure HTTPS, omitted here.

2.2, ELB set

2.2.1, create the target group

After creating the target group, remember to add a registered instance, it is our EC2.

AWS cloud offering CloudFront + ELB + EC2 + S3 construct virtual host static and dynamic separation site

2.2.2, create a load balancer

AWS cloud offering CloudFront + ELB + EC2 + S3 construct virtual host static and dynamic separation site

We can add HTTPS listener (non-essential), so that we can access the encrypted, you can set various rules, we do not need to be set here, plus on the line.

AWS cloud offering CloudFront + ELB + EC2 + S3 construct virtual host static and dynamic separation site

Then the DNS to our ELB, use HTTP and HTTPS access our two virtual hosts, each page can be displayed are normal, applications for certificates, we can use AWS services of ACM.

Guess you like

Origin blog.51cto.com/wzlinux/2412973