Set up a Web Server and Host a Website on Linode
- Install NGINX:
1
sudo apt install nginx
- Create an NGINX configuration file called
/etc/nginx/conf.d/example.com.conf
(replace this and each instance ofexample.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/*; }
- 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 forexample.com
:1
sudo mkdir -p /var/www/example.com
- Give ownership of this directory to your limited user account:
1
sudo chown username:username /var/www/example.com
- Disable the default NGINX welcome page:
1
sudo rm /etc/nginx/sites-enabled/default
- Test the NGINX configuration for errors:
1
sudo nginx -t
- If there are no errors, reload the configuration:
1
sudo nginx -s reload
- 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 usescp
from your local computer:1
scp -r my-website/* username@<linode-ip-address:/var/www/example.com/
- 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
- Check that NGINX loaded successfully:
1
sudo systemctl status nginx