Article 10.1 - Nginx — Install & Production Config
Short answerapt install nginx, create site in sites-available, enable site, test config, obtain TLS with Certbot. Distribution-specific install guides linked below.
Overview
Nginx serves static files and reverse-proxies apps on unmanaged VPS. You install and configure it inside the guest OS.
Install
apt install nginx -y
systemctl enable nginx --now
nginx -v
curl -I http://localhostProduction server block
Save as /etc/nginx/sites-available/example.com — adjust paths, PHP version, and domain:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
add_header Strict-Transport-Security "max-age=63072000" always;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
root /var/www/example.com/public;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginxInstall walkthroughs: NGINX on Ubuntu/Debian, NGINX on AlmaLinux/Rocky.
Frequently Asked Questions
502 Bad Gateway after Nginx setup?
PHP-FPM or upstream app is down — systemctl status php8.2-fpm. See common error reference Article 5.8.
No TLS yet?
Use Certbot — Let's Encrypt with Certbot or Article 10.2.
Related Articles
Need More Help?
Search this knowledgebase for related guides. If the issue persists, open a ticket at billing.vpsgrid.net with your service ID, primary IP, and steps already tried. See What Information to Include in a Support Request and Security Responsibilities on Unmanaged VPS for scope and required details.
Was this answer helpful?