Setting up Nginx

  1. Install ngingx:

    apt install nginx

  2. Enable and start the systemd service:

    systemctl enable nginx.service
    systemctl start nginx.service

  3. Configure and enable the webpage: Under /etc/nginx/ should be two directories listed.
    sites-available and sites-enabled.
    sites-available contains config files for exisitng webpages, while sites-enabled contains softlinks to config files in sites-available.

    1. Create a config file (e.g. example.com.conf) in sites-available with the following content:
      server {
      	listen 80;
      
      	server_name example.com;
      
      	root path/to/index.html;
      	index index.html;
      
      	location / {
      		index index.html index.html;
      	}
      }
      Make sure to check the nginx documentation
      This config is really basic. There is much more to be configured.
    2. Create the softlink in sites-enabled:
      cd /etc/nginx/site-enabled
      ln -s /etc/nginx/sites-available/example.com.conf example.com.conf
    3. Reload config:
      nginx -s reload

HTTPS

I suggest using Let's Encrypt for this.

Basic Authentication

  1. Install apache2-utils
  2. Generate a new password file
    sudo htpasswd -c /etc/nginx/.htpasswd admin
  3. Turn on basic http authentication
    location /admin {
      try_files $uri $uri/ =404;
      auth_basic "Restricted Content";
      auth_basic_user_file /etc/nginx/.htpasswd;
    }


Comments