Server
Proper nginx configuration is crucial for the proper functioning of the server. The following configuration is a good starting point for a server setup. This include proper configuration for let's encrypt SSL certificates, www to non-www redirection and http to https redirection.
server {
listen 443 ssl http2;
server_name labelize.food;
ssl_certificate /etc/letsencrypt/live/www.labelize.food/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.labelize.food/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /var/www/html;
index index.html;
location / {
disable_symlinks off;
try_files $uri $uri/ =404;
}
}
server {
listen 443 ssl http2;
server_name www.labelize.food;
ssl_certificate /etc/letsencrypt/live/www.labelize.food/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.labelize.food/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# Redirect www to non-www
return 301 https://labelize.food$request_uri;
}
server {
listen 80;
server_name labelize.food www.labelize.food;
# Redirect all HTTP requests to HTTPS (and handle www to non-www here)
return 301 https://labelize.food$request_uri;
}