Amazon Cloudfront(CDN) with multiple domains on a single droplet.

July 28, 2015 3.2k views
Configuration Management LEMP DNS Ubuntu

Hi guys,

I wanted to ask how to set up Nginx web server to allow Amazon Cloudfront(CDN) to origin pull from a domain(www.yyyy.com) when a subdomain is entered in the url(cdn.yyyy.com).

For instance:

I want to set up

i) subdomain cdn.xxxx.com to point to xxxx.cloudfront.net which in turn pulls from the origin www.xxxx.com

ii)subdomain cdn.yyyy.com to point to yyyy.cloudfront.net which in turn pulls from the origin www.yyyy.com

iii)subdomain cdn.zzzz.com to point to zzzz.cloudfront.net which in turn pulls from the origin www.zzzz.com

I have created server blocks for www.xxxx.com www.yyyy.com www.zzzz.com. xxx.xxxx.com is the default server.

I intend to create in config file of server block yyyy.com for ii):

server {
listen 80;
listen [::]:80;

root /var/www/yyyy.com/html;
index index.php index.html index.htm;

server_name yyyy.com www.yyyy.com .yyyy.com;

location / {

try_files $uri $uri/ =404;

}
server{
listen 80;
listen [::]:80;

root /var/www/cdn.yyyy.com/html;
index index.php index.html index.htm;

server_name cdn.yyyy.com .cdn.yyyy.com;

location / {
try_files $uri $uri/ =404;
}

Is this correct?

Should I create directory /var/www/cdn.yyyy.com/html also?What about DNS records? Do I use CNAME or A record?

Thanks.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Previously I used aliasnames but it keep pointing to the default server address html page(www.xxxx.com) which is not what I want

server {
listen 80;
listen [::]:80;

root /var/www/yyyy.com/html;
index index.php index.html index.htm;

server_name yyyy.com www.yyyy.com cdn.yyyy.com;

location / {

try_files $uri $uri/ =404;

}

1 comment
  • I am new aswell for easy installation of digital ocean droplet nginx (wordpress) is Easyengine go here at rtcamp.com .
    you can also try server pilot but you have to enable nginx on it but its off by default
    you can install multi sites on same droplet after dns is configured to your droplet .

    they also have tutorial for CDN w3 plugin to use cloud front aws
    https://rtcamp.com/tutorials/cdn/amazon-cloudfront-wordpress-w3-total-cache/

    i am not sure if you can use the same cloud front cdn for multi domain i am doing research on it now .
    sorry i dont know this things very well either .
    good luck

Be the first one to answer this question.