Site Logo
mnjm

Hosting a Static Website on Nginx in Linux

Posted on 3 mins

Nginx Hosting

Prerequisites

Steps

1. Install nginx and copy static site to a remote dir

2. Nginx Site Configuration

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

    server_name mnjm.fr.to;

    root /mnt/data/mnjm_site;
    charset utf-8;

    error_page 404 /404.html;
}
Your site should be up my now.

3. Setting up HTTPs

sudo iptables -I INPUT -p tcp --dport 443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -I OUTPUT -p tcp --sport 443 -m conntrack --ctstate ESTABLISHED -j ACCEPT
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Your site should be up with https certification, enjoy!

4. Final Step - Optional

listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
Now you site should work with http2 enabled.

References