Snippets Nginx / Basic CDN

Basic CDN

By Marcelo Fernandes Jul 09, 2017

Creating a Basic CDN (Content Delivery Network)

Nginx is a very valuable tool for creating a CDN, and its basic configurations basically sets up an easy and
almost ready to go CDN. So lets take advantage of it and see how small modifications can build up a cool CDN for our projects.

Step 1: Downloading the dependencies.

# Using Debian its pretty straight forward:
sudo apt-get install nginx

Now nginx is installed, and it has created some folders that we are gonna visit right now.
Step 2: Changing the file serving directories

# Move to the directory
cd /etc/nginx/sites-available
# You should have a pre-installed file "default"
nano default

You should see a line like this one in your 'default' file:

# Change this folder to whatever folder you want to be your cdn storage.
root /var/www/assets

Save and Close the File.

# Symlink this file to the folder sites-enabled
cp default ../sites-available

Step 3: Use your CDN
Now if you put a file "file.txt" in your nginx-root folder, it will be served at: "your-ip.addres/file.txt"

Notes


References:


link 1