Commando’s
nginx -t config testen
nginx -s reload herladen zonder downtime
systemctl restart nginx
nginx -V build + modules
Statische site
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Reverse proxy
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
TLS + redirect
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# ...
}
server { # http → https
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
Handig
location /static/ { expires 30d; add_header Cache-Control "public"; }
client_max_body_size 50m; # upload-limiet
location /api/ { proxy_pass http://backend; }
Sites staan meestal in /etc/nginx/sites-available/ met een symlink in
sites-enabled/, of in /etc/nginx/conf.d/*.conf.