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.
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.
2.2.2, create a load balancer
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.
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.