Aller au contenu
Se connecter
VPS

Déployer un site web avec Nginx et Let's Encrypt

Configuration complète d'un serveur web Nginx avec SSL gratuit pour héberger votre site.

05 mars 2026 473 vues ~1 min de lecture 21 utile

Installation de Nginx

sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginx

Configuration du virtual host

Créez /etc/nginx/sites-available/monsite.conf :

server {
    listen 80;
    server_name monsite.fr www.monsite.fr;
    root /var/www/monsite/public;
    index index.html index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\. {
        deny all;
    }
}

Activez le site :

sudo ln -s /etc/nginx/sites-available/monsite.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

SSL avec Certbot

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d monsite.fr -d www.monsite.fr

Optimisations Nginx

Ajoutez dans votre bloc server :

# Compression Gzip
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;

# Cache assets statiques
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff2)$ {
    expires 30d;
    add_header Cache-Control "public, immutable";
}

# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;

Conclusion

Nginx + Let's Encrypt vous donnent un serveur web performant et sécurisé en quelques minutes. Combinez avec PHP-FPM pour héberger Laravel, WordPress ou toute application PHP.

Tags

nginx ssl web lets-encrypt

Cet article vous a été utile ?

Aidez-nous à améliorer notre documentation.

Merci pour votre retour !