NGINX Configuration#
Install NGINX on Ubuntu#
sudo apt update && sudo apt install nginx -y && sudo nginx -v
Reference: linode - Installing NGINX Open Source
The Basic Terms#
Reference: linode - How to Configure NGINX
Configure NGINX to serve static files#
server {
listen 80;
location / {
# static files
root /usr/share/nginx/html;
server_name domain.com;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
Reference: NGINX Docs - Serving Static Content
Configure NGINX as a reverse proxy#
server {
listen 80;
location / {
# static files
root /usr/share/nginx/html;
server_name domain.com;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
proxy_pass http://127.0.0.1:8080;
}
}
Reference: NGINX Docs - NGINX Reverse Proxy
HTTP Basic Authentication#
Install password file creation utility
sudo apt update && sudo apt install apache2-utils -y
Create password file & the first user
sudo htpasswd -c /etc/nginx/.htpasswd username
Add the second user to the password file
sudo htpasswd /etc/nginx/.htpasswd username2
NGINX config
server {
auth_basic "Protected Area";
auth_basic_user_file /etc/nginx/.htpasswd;
location /public/ {
auth_basic off;
}
}