Documentation du Dr FRAPPE

Ce wiki regroupe les résultats de mes expériences en informatique accumulés au cours de mes recherches sur le net.

Dans la mesure du possible, j'ai cité mes sources ; il en manque certainement… :-)

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tutoriel:internet:nginx:debutant:start [2020/12/14 10:21] – [Structure du fichier de configuration] admintutoriel:internet:nginx:debutant:start [2022/08/13 22:15] (Version actuelle) – modification externe 127.0.0.1
Ligne 14: Ligne 14:
  
 Par défaut, le fichier de configuration est /usr/local/nginx/conf/nginx.conf, /etc/nginx/nginx.conf ou /usr/local/etc/nginx/nginx.conf. Par défaut, le fichier de configuration est /usr/local/nginx/conf/nginx.conf, /etc/nginx/nginx.conf ou /usr/local/etc/nginx/nginx.conf.
-====== Démarrage, arrêt et rechargement de la configuration ======+ 
 +===== Démarrage, arrêt et rechargement de la configuration =====
  
 Pour démarrer nginx, lancez le fichier exécutable. Pour démarrer nginx, lancez le fichier exécutable.
  
 Une fois démarré, nginx peut être contrôlé en lançant l'exécutable avec le paramètre -s. Utilisez la syntaxe suivante : <cli prompt='$ '>...@...:~$ nginx -s signal</cli>où le signal peut être : Une fois démarré, nginx peut être contrôlé en lançant l'exécutable avec le paramètre -s. Utilisez la syntaxe suivante : <cli prompt='$ '>...@...:~$ nginx -s signal</cli>où le signal peut être :
-  stop+  stop
   : arrêt rapide   : arrêt rapide
-  quit+  quit
   : arrêt en douceur   : arrêt en douceur
-  reload+  reload
   : rechargement du fichier de configuration   : rechargement du fichier de configuration
-  reopen+  reopen
   : réouverture des fichiers de log   : réouverture des fichiers de log
  
Ligne 36: Ligne 37:
  
 Pour obtenir la liste de tous les processus nginx en cours d'exécution :<cli prompt='$ '>...@...:~$ ps -ax | grep nginx</cli> Pour obtenir la liste de tous les processus nginx en cours d'exécution :<cli prompt='$ '>...@...:~$ ps -ax | grep nginx</cli>
-====== Structure du fichier de configuration ======+ 
 +===== Structure du fichier de configuration =====
  
 Les modules de Nginx sont contrôlés par des directives du fichier de configuration. Les modules de Nginx sont contrôlés par des directives du fichier de configuration.
Ligne 51: Ligne 53:
  
 Le reste d'une ligne après un # est un commentaire. Le reste d'une ligne après un # est un commentaire.
-====== Servir du contenu statique ====== 
  
-====== Mise en place d'un proxy simple ======+===== Servir du contenu statique ===== 
 + 
 +An important web server task is serving out files (such as images or static HTML pages). 
 + 
 +You will implement an example where, depending on the request, files will be served from different local directories: /data/www (which may contain HTML files) and /data/images (containing images). 
 + 
 +This will require editing of the configuration file and setting up of a server block inside the http block with two location blocks. 
 + 
 +First, create the /data/www directory and put an index.html file with any text content into it and create the /data/images directory and place some images in it. 
 + 
 +Next, open the configuration file. The default configuration file already includes several examples of the server block, mostly commented out. For now comment out all such blocks and start a new server block:<code - > 
 +http { 
 +    server { 
 +    } 
 +}</code> 
 + 
 +Generally, the configuration file may include several server blocks distinguished by ports on which they listen to and by server names. 
 + 
 +Once nginx decides which server processes a request, it tests the URI specified in the request’s header against the parameters of the location directives defined inside the server block. 
 + 
 +Add the following location block to the server block:<code - > 
 +location / { 
 +    root /data/www; 
 +}</code> 
 + 
 +This location block specifies the “/” prefix compared with the URI from the request. 
 + 
 +For matching requests, the URI will be added to the path specified in the root directive, that is, to /data/www, to form the path to the requested file on the local file system. 
 + 
 +If there are several matching location blocks nginx selects the one with the longest prefix. 
 + 
 +The location block above provides the shortest prefix, of length one, and so only if all other location blocks fail to provide a match, this block will be used. 
 + 
 + Next, add the second location block: 
 + 
 +location /images/ { 
 +    root /data; 
 +
 + 
 +It will be a match for requests starting with /images/ (location / also matches such requests, but has shorter prefix). 
 + 
 +The resulting configuration of the server block should look like this:<code - > 
 +server { 
 +    location / { 
 +        root /data/www; 
 +    } 
 + 
 +    location /images/ { 
 +        root /data; 
 +    } 
 +}</code> 
 + 
 +This is already a working configuration of a server that listens on the standard port 80 and is accessible on the local machine at http://localhost/
 + 
 +In response to requests with URIs starting with /images/, the server will send files from the /data/images directory. 
 + 
 +For example, in response to the http://localhost/images/example.png request nginx will send the /data/images/example.png file. 
 + 
 +If such file does not exist, nginx will send a response indicating the 404 error. 
 + 
 +Requests with URIs not starting with /images/ will be mapped onto the /data/www directory. 
 + 
 +For example, in response to the http://localhost/some/example.html request nginx will send the /data/www/some/example.html file. 
 + 
 +To apply the new configuration, start nginx if it is not yet started or send the reload signal to the nginx’s master process, by executing:<cli prompt='$ '>...@...:~$ nginx -s reload</cli> 
 + 
 +<WRAP center round tip 60%> 
 +In case something does not work as expected, you may try to find out the reason in access.log and error.log files in the directory /usr/local/nginx/logs or /var/log/nginx. 
 +</WRAP> 
 + 
 +===== Mise en place d'un proxy simple =====
  
-====== Mise en place du proxy FastCGI ======+===== Mise en place du proxy FastCGI =====
  
-====== Voir aussi ======+===== Voir aussi =====
  
   * **(en)** [[https://nginx.org/en/docs/beginners_guide.html#conf_structure]]   * **(en)** [[https://nginx.org/en/docs/beginners_guide.html#conf_structure]]