Home set up a web server and host a website
Post
Cancel

set up a web server and host a website

Set up a Web Server and Host a Website on Linode

  1. Install NGINX:
    1
    
    sudo apt install nginx
    
  2. Create an NGINX configuration file called /etc/nginx/conf.d/example.com.conf (replace this and each instance of example.com with your site’s name) and add the following content:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
    server {
    listen         80;
    listen         [::]:80;
    server_name    example.com www.example.com;
    root           /var/www/example.com;
    index          index.html;
    gzip             on;
    gzip_comp_level  3;
    gzip_types       text/plain text/css application/javascript image/*;
    }
    
  3. The configuration above tells NGINX to look for your site’s files in /var/www/example.com. Create this directory now, substituting your domain name for example.com:
    1
    
    sudo mkdir -p /var/www/example.com
    
  4. Give ownership of this directory to your limited user account:
    1
    
    sudo chown username:username /var/www/example.com
    
  5. Disable the default NGINX welcome page:
    1
    
    sudo rm /etc/nginx/sites-enabled/default
    
  6. Test the NGINX configuration for errors:
    1
    
    sudo nginx -t
    
  7. If there are no errors, reload the configuration:
    1
    
    sudo nginx -s reload
    
  8. Copy the static files from your local computer to the target directory on your Linode. There are many ways to accomplish this. For example, if your site files are stored in a directory called my-website on your computer, you can use scp from your local computer:
    1
    
    scp -r my-website/* username@<linode-ip-address:/var/www/example.com/
    
  9. Activate the firewall using the built-in NGINX plugin for UFW:
    1
    2
    3
    
    sudo ufw allow 'NGINX Full'
    sudo ufw allow ssh
    sudo ufw enable
    
  10. Check that NGINX loaded successfully:
    1
    
     sudo systemctl status nginx
    
This post is licensed under CC BY 4.0 by the author.