Serveur Debian

Administration con centré . com !

Serveur Debian

IP-ADRESSE-DE-VOTRE-SERVEUR
votre nom de domaine

NGNIX

                  +------------------+
                  |  Utilisateurs    |
                  +---------+--------+
                            |
                            v                            
                  +------------------+
                  |  Nginx + PHP     |
                  +---------+--------+

Installe

sudo apt install nginx -y
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-xml php8.2-mbstring php8.2-curl -y

sudo nginx -t
sudo systemctl status nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log



Installer le module Nginx dans Webmin :
Allez dans "Webmin Configuration / Webmin Modules / Instale : Module tiers de https://www.justindhoffman.com/sites/justindhoffman.com/files/nginx-0.10.wbm_.gz

Configurer son nom de domaine : nomdedomaine.fr

sudo mkdir -p /var/www/nomdedomaine.fr
sudo chown -R www-data:www-data /var/www/nomdedomaine.fr
sudo chmod -R 755 /var/www/nomdedomaine.fr  

sudo nano /etc/nginx/sites-available/nomdedomaine.fr

server {
    listen 80;
    server_name nomdedomaine.fr www.nomdedomaine.fr;

    server_tokens off;

    root /var/www/nomdedomaine.fr;
    index index.html index.htm index.php;

    access_log /var/log/nginx/nomdedomaine.fr.access.log;
    error_log /var/log/nginx/nomdedomaine.fr.error.log;


    add_header Cache-Control "public";
    add_header Strict-Transport-Security "max-age=63072000";  # durée pendant laquelle le navigateur doit se souvenir que le site ne doit être accessible que via HTTPS
    add_header X-Frame-Options "DENY";          # Blocage de l'affichage dans un cadre [iframe-frame-object html] Protection contre le clickjacking 
    add_header X-Frame-Options "SAMEORIGIN";    # Autirise les cadre si la requête provient de la même domaine.


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

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

    location ~ /\.ht {
        deny all;
    }
}

    



sudo ln -s /etc/nginx/sites-available/nomdedomaine.fr /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

echo "<?php echo('Bonjour nomdedomaine.fr');?>" | sudo tee /var/www/nomdedomaine.fr/index.php
echo "<?php phpinfo();?>" | sudo tee /var/www/nomdedomaine.fr/info.php

http://www.nomdedomaine.fr/
http://nomdedomaine.fr/info.php



    

sudo apt install certbot python3-certbot-nginx                      
sudo certbot --nginx -d nomdedomaine.fr -d www.nomdedomaine.fr
    

certbot va installer la certification et modifier le fichier

    cat /etc/nginx/sites-available/nomdedomaine.fr



    server {
    server_name nomdedomaine.fr www.nomdedomaine.fr;

    root /var/www/nomdedomaine.fr;
    index index.html index.htm index.php;

    access_log /var/log/nginx/nomdedomaine.fr.access.log;
    error_log /var/log/nginx/nomdedomaine.fr.error.log;

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

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

    location ~ /\.ht {
        deny all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/nomdedomaine.fr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nomdedomaine.fr/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
}
server {
    if ($host = www.nomdedomaine.fr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = nomdedomaine.fr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name nomdedomaine.fr www.nomdedomaine.fr;
    return 404; # managed by Certbot
}



    


sudo certbot certonly --nginx -d nomdedomaine.fr -d www.nomdedomaine.fr
sudo tail -f/var/log/letsencrypt/letsencrypt.log
sudo certbot certificates
sudo certbot delete --cert-name nomdedomaine.fr
sudo certbot renew
sudo certbot install --cert-name nomdedomaine.fr -d www.nomdedomaine.fr

    


Suppréssion NGNIX

sudo systemctl stop nginx
sudo apt-get purge nginx nginx-common nginx-full -y
sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx
sudo rm -rf /var/www/html
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo systemctl status nginx