Nginx is a fast, efficient web server and reverse proxy. Here's how to install and secure it on Ubuntu.
1. Install
sudo apt update
sudo apt install nginx -y
sudo systemctl enable --now nginx
Allow it through the firewall: sudo ufw allow 'Nginx Full'.
2. Create a server block
Add /etc/nginx/sites-available/example.com with your server_name and web root, then symlink it into sites-enabled/ and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
3. Add HTTPS
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com
4. Harden it
- Hide the version:
server_tokens off;innginx.conf. - Add security headers (HSTS, X-Content-Type-Options, X-Frame-Options).
- Enable rate limiting on login endpoints to slow brute-force attacks.
Reload after each change with sudo nginx -t && sudo systemctl reload nginx. You now have a fast, secure web server ready for production.