Deploy a site with Nginx
Install Nginx, configure a vhost and upload your application or static site.
Ready to start your service? Check offers and order online.
View offers and orderOverview
Nginx is a powerful web server, ideal for hosting static sites, PHP-FPM applications, reverse proxy or APIs. This guide installs Nginx on Debian/Ubuntu and configures a demo site.
Installation
apt update
apt install nginx -y
systemctl enable nginx
systemctl start nginxMake sure Nginx answers: Open http://ADRESSE_IP in your browser. The default "Welcome to nginx" page must be displayed.
ufw allow 'Nginx Full'. See guide Configure a UFW firewall.
File structure
/var/www/, root of websites/etc/nginx/sites-available/, configurations available/etc/nginx/sites-enabled/, activated sites (symbolic links)/var/log/nginx/, access and error logs
Create a static site
-
Create site directory
mkdir -p /var/www/monsite.fr/html chown -R www-data:www-data /var/www/monsite.fr -
Add Home Page
echo '<!DOCTYPE html><html><head><title>Mon site</title></head> <body><h1>Bienvenue sur monsite.fr</h1></body></html>' \ > /var/www/monsite.fr/html/index.html -
Create the virtual host
Create
/etc/nginx/sites-available/monsite.fr:
server {
listen 80;
listen [::]:80;
server_name monsite.fr www.monsite.fr;
root /var/www/monsite.fr/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/monsite.fr.access.log;
error_log /var/log/nginx/monsite.fr.error.log;
}-
Enable site
ln -s /etc/nginx/sites-available/monsite.fr /etc/nginx/sites-enabled/ nginx -t systemctl reload nginxnginx -tvalidate the syntax before reloading. Never reload if the test fails.
Point your domain name
In your registry, create a A record pointing to the IPv4 of your VPS. DNS Propagation: a few minutes at 24 h. Test with:
dig +short monsite.frEnable HTTPS with Let's Encrypt
Install Certbot:
apt install certbot python3-certbot-nginx -y
certbot --nginx -d monsite.fr -d www.monsite.frFollow the wizard (e-mail, conditions, HTTP redirect → HTTPS recommended). The certificate is automatically renewed via a timer systemd.
Renewal test:
certbot renew --dry-runHosting a PHP application (optional)
apt install php-fpm -yAdd in your block server :
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}Adapt PHP (php8.1-fpm, php8.2-fpm...) according to ls /run/php/.
Troubleshooting
- 502 Bad Gateway, PHP-FPM stopped or bad socket in config.
- 403 Forbidden, Incorrect Rights on
/var/www/or missing index. - Default site displayed, Check
server_nameand the link insites-enabled.
Check the logs: tail -f /var/log/nginx/error.log
Next steps
- Mount additional IP for a second isolated site
- Use the Management Panel