18 November 2021
Linux
NGINX Open Source ou NGINX est un logiciel libre de serveur Web ainsi qu'un proxy inverse écrit par Igor Sysoev.
Table des matières
sudo apt install nginx
sudo service nginx start
cd /etc/nginx
ls -l
total 64
drwxr-xr-x 2 root root 4096 mai 25 19:10 conf.d
-rw-r--r-- 1 root root 1077 fév 4 2019 fastcgi.conf
-rw-r--r-- 1 root root 1007 fév 4 2019 fastcgi_params
-rw-r--r-- 1 root root 2837 fév 4 2019 koi-utf
-rw-r--r-- 1 root root 2223 fév 4 2019 koi-win
-rw-r--r-- 1 root root 3957 fév 4 2019 mime.types
drwxr-xr-x 2 root root 4096 mai 25 19:10 modules-available
drwxr-xr-x 2 root root 4096 sep 22 17:35 modules-enabled
-rw-r--r-- 1 root root 1490 fév 4 2019 nginx.conf
-rw-r--r-- 1 root root 180 fév 4 2019 proxy_params
-rw-r--r-- 1 root root 636 fév 4 2019 scgi_params
drwxr-xr-x 2 root root 4096 sep 24 04:14 sites-available
drwxr-xr-x 2 root root 4096 sep 22 17:35 sites-enabled
drwxr-xr-x 2 root root 4096 sep 22 17:35 snippets
-rw-r--r-- 1 root root 664 fév 4 2019 uwsgi_params
-rw-r--r-- 1 root root 3071 fév 4 2019 win-utf
cd /var/www/
sudo mkdir /var/www/site1
sudo mkdir /var/www/site2
sudo chown david:david site1 site2
ls -l
total 12
drwxr-xr-x 2 root root 4096 sep 24 04:16 html
drwxr-xr-x 2 david david 4096 sep 22 19:16 site1
drwxr-xr-x 2 david david 4096 sep 22 19:07 site2
touch /var/www/site1/index.html
touch /var/www/site2/index.html
vim /var/www/site1/index.html
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/site1
sudo vim /etc/nginx/sites-available/site1
# site1
server {
listen 80;
listen [::]:80;
root /var/www/site1;
index index.html index.htm index.nginx-debian.html;
server_name site1.local;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
sudo cp /etc/nginx/sites-available/site1 /etc/nginx/sites-available/site2
sudo vim /etc/nginx/sites-available/site2
# site2
server {
listen 80;
listen [::]:80;
root /var/www/site2;
index index.html index.htm index.nginx-debian.html;
server_name site2.local;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
sudo vim /etc/hosts
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 site1.local
127.0.0.1 site2.local
sudo ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2 /etc/nginx/sites-enabled/
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service nginx reload
curl site1.local
Bienvenue sur le site 1
cd /var/www/site1
code .
sudo apt install php7.4-fpm
sudo apt install php7.4-cli
sudo mkdir /var/www/site3
cd /var/www
sudo chown david:david site3
touch /var/www/site3/index.php
vim /var/www/site3/index.php
puis echap puis taper :x pour fermer est enristrer le fichiersudo vim /etc/nginx/sites-available/site3
# Site3
server {
listen 80;
listen [::]:80;
root /var/www/site3;
# Add index.php to the list if you are using PHP
index index.html index.php index.nginx-debian.html;
server_name site3.local;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
sudo ln -s /etc/nginx/sites-available/site3 /etc/nginx/sites-enabled/
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 site1.local
127.0.0.1 site2.local
127.0.0.1 site3.local
sudo service nginx reload
sudo service php7.4-fpm restart