Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tutoriel:internet:nginx:debutant:start [2020/12/14 09:38] – [Démarrage, arrêt et rechargement de la configuration] admin | tutoriel: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 / | Par défaut, le fichier de configuration est / | ||
| - | ====== 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' | Une fois démarré, nginx peut être contrôlé en lançant l' | ||
| - | | + | |
| : arrêt rapide | : arrêt rapide | ||
| - | | + | |
| : arrêt en douceur | : arrêt en douceur | ||
| - | | + | |
| : rechargement du fichier de configuration | : rechargement du fichier de configuration | ||
| - | | + | |
| : réouverture des fichiers de log | : réouverture des fichiers de log | ||
| Ligne 33: | Ligne 34: | ||
| </ | </ | ||
| - | ====== Structure | + | Les modifications |
| - | ====== Servir du contenu statique ====== | + | Pour obtenir la liste de tous les processus nginx en cours d' |
| + | |||
| + | ===== Structure du fichier de configuration ===== | ||
| + | |||
| + | Les modules de Nginx sont contrôlés par des directives du fichier de configuration. | ||
| + | |||
| + | Les directives sont : | ||
| + | * des directives simples, composées du nom et des paramètres séparés par des espaces et terminées par un point-virgule ( ;). | ||
| + | * et des directives de bloc, de même structure qu'une directive simple, mais au lieu du point-virgule, | ||
| + | |||
| + | Une directive de bloc peut contenir d' | ||
| + | |||
| + | Les directives placées dans le fichier de configuration en dehors de tout contexte sont considérées comme étant dans le contexte principal. | ||
| + | |||
| + | Les directives events et http résident dans le contexte principal, le server dans http, et location dans server. | ||
| + | |||
| + | Le reste d'une ligne après un # est un commentaire. | ||
| + | |||
| + | ===== 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: | ||
| + | |||
| + | 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 / | ||
| + | |||
| + | 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:< | ||
| + | http { | ||
| + | server { | ||
| + | } | ||
| + | }</ | ||
| + | |||
| + | 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:< | ||
| + | location / { | ||
| + | root / | ||
| + | }</ | ||
| + | |||
| + | 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:< | ||
| + | server { | ||
| + | location / { | ||
| + | root / | ||
| + | } | ||
| + | |||
| + | location /images/ { | ||
| + | root /data; | ||
| + | } | ||
| + | }</ | ||
| + | |||
| + | 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:// | ||
| + | |||
| + | In response to requests with URIs starting with /images/, the server will send files from the / | ||
| + | |||
| + | For example, in response to the http:// | ||
| + | |||
| + | 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:// | ||
| + | |||
| + | To apply the new configuration, | ||
| + | |||
| + | <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 / | ||
| + | </ | ||
| - | ====== Mise en place d'un proxy simple | + | ===== 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:// | * **(en)** [[https:// | ||