Nginx is a fast and lightweight web server. Here is how to configure it for your website:
Installation
apt update && apt install -y nginxsystemctl enable nginx
systemctl start nginx
Basic configuration
Create the file/etc/nginx/sites-available/my-site:server {
listen 80;
server_name my-domain.com www.my-domain.com;
root /var/www/my-site;
index index.html index.php;
location / {
try_files $uri $uri/ /index.html;
}
}
Enable the site
ln -s /etc/nginx/sites-available/my-site /etc/nginx/sites-enabled/nginx -t
systemctl reload nginx
SSL with Let's Encrypt
apt install certbot python3-certbot-nginxcertbot --nginx -d my-domain.com
Useful commands
nginx -t # test the configurationsystemctl reload nginx # reload without a restart
systemctl restart nginx # full restart
tail -f /var/log/nginx/error.log # logs
Any questions? Write here!