How to build a CDN Server

1. Update the system software packages to the latest version

yum -y update

2. Install Nginx HTTP server from the EPEL repository using the YUM package manager


yum install epel-release
yum install nginx
    

3. Start Nginx web server for the first time and enable it to start automatically at system boot


systemctl start nginx
systemctl enable nginx
    

4. Allow web traffic on Nginx by updating the system firewall rules


firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload
    

Note: For testing purposes, you can remove the firewalld and flush the iptables to open all connections. However, do not do this on a Production Server.

yum remove firewalld && iptables -F

5. Verify Nginx server by accessing the default Nginx page

Visit http://SERVER_DOMAIN_NAME_OR_IP in your browser, replacing the placeholder with your server’s domain name or IP address. You should see the default Nginx test page.

Nginx Important Files and Directories

  • Default server root directory: /etc/nginx
  • Main Nginx configuration file: /etc/nginx/nginx.conf
  • Server block (virtual hosts) configurations: /etc/nginx/conf.d
  • Default server document root directory: /usr/share/nginx/html

6. Set up the cache for static content with Nginx


cd /etc/nginx/conf.d/ #changes directory

vim cdn.conf #create a config file with the content provided below

# Configuration content goes here

save and quit the file
    

7. Create a cache directory at /mnt/nginx/cdn (cache storage)


mkdir /mnt/nginx/cdn
chown -R nginx.nginx /mnt/nginx/
    

Conclusion: This is a basic CDN server setup for a single point within a country. To set up multiple servers in different countries to serve your clients, you will need to use the Nginx Geo module.

If you need further assistance or have questions, please feel free to reach out to us at linuxscritpshub@gmail.com.

Thank you for following our guide on setting up a static content CDN with Linux (Centos 7) using Nginx HTTP server.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *