mirror of
https://github.com/YunoHost/doc.git
synced 2024-09-03 20:06:26 +02:00
Upgrade NGINX conf
This commit is contained in:
parent
cea0b2d4e1
commit
19a1df1093
2 changed files with 76 additions and 41 deletions
pages/06.contribute/10.packaging_apps/09.nginx
|
@ -10,57 +10,71 @@ routes:
|
||||||
Ce tutoriel a pour but d’aider à la mise en place d’une configuration NGINX pour le packaging d’application.
|
Ce tutoriel a pour but d’aider à la mise en place d’une configuration NGINX pour le packaging d’application.
|
||||||
|
|
||||||
#### Configuration NGINX
|
#### Configuration NGINX
|
||||||
La configuration doit être mise dans `conf/nginx.conf`. Il s’agira d’utiliser **FastCGI** ou un **proxy_pass** suivant l’application :
|
|
||||||
* **FastCGI** est utilisé dans les applications PHP :
|
|
||||||
```nginx
|
|
||||||
location YNH_EXAMPLE_PATH {
|
|
||||||
alias YNH_WWW_PATH ;
|
|
||||||
if ($scheme = http) {
|
|
||||||
rewrite ^ https://$server_name$request_uri? permanent;
|
|
||||||
}
|
|
||||||
index index.php;
|
|
||||||
try_files $uri $uri/ index.php;
|
|
||||||
location ~ [^/]\.php(/|$) {
|
|
||||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
|
||||||
fastcgi_pass unix:/var/run/php5-fpm.sock;
|
|
||||||
fastcgi_index index.php;
|
|
||||||
include fastcgi_params;
|
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
|
||||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
|
||||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
La configuration doit être mise dans `conf/nginx.conf`. Il s’agira d’utiliser **FastCGI** ou un **proxy_pass** suivant l’application :
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
* **FastCGI** est utilisé dans les applications PHP :
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
|
location __PATH__/ {
|
||||||
|
|
||||||
|
proxy_pass http://127.0.0.1:__PORT__/;
|
||||||
|
proxy_redirect off;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Host $server_name;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* **`proxy_pass`** dans le cas d’applications Python, Node.js, Go et Java :
|
* **`proxy_pass`** dans le cas d’applications Python, Node.js, Go et Java :
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
location YNH_EXAMPLE_PATH/ {
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
rewrite ^YNH_EXAMPLE_PATH$ YNH_EXAMPLE_PATH/ permanent;
|
location __PATH__/ {
|
||||||
proxy_pass http://YNH_EXEMPLE_DOMAIN:YNH_EXAMPLE_PORT/;
|
|
||||||
|
proxy_pass http://127.0.0.1:__PORT__/;
|
||||||
|
proxy_redirect off;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_buffering off;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Host $server_name;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Script d’installation
|
#### Script d’installation
|
||||||
|
|
||||||
Il s’agit de modifier le fichier `conf/nginx.conf` avec les paramètres de l’application. Pour cela, on utilise des termes génériques `YNH_EXAMPLE_PATH` que l’on modifie par des valeurs souhaitées avec la commande `sed` :
|
Il s’agit de modifier le fichier `conf/nginx.conf` avec les paramètres de l’application. Pour cela, on utilise des termes génériques `YNH_EXAMPLE_PATH` que l’on modifie par des valeurs souhaitées avec la commande `sed` :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
||||||
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
|
||||||
sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
|
||||||
```
|
```
|
||||||
Il faut ensuite déplacer ce fichier de configuration dans la configuration de NGINX, puis recharger la configuration de NGINX :
|
|
||||||
|
Il faut ensuite déplacer ce fichier de configuration dans la configuration de NGINX, puis recharger la configuration de NGINX :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
```
|
```
|
||||||
|
|
||||||
Si NGINX ne redémarre pas, il se peut que le fichier de configuration ne soit pas correct.
|
Si NGINX ne redémarre pas, il se peut que le fichier de configuration ne soit pas correct.
|
||||||
|
|
||||||
#### Script de suppression
|
#### Script de suppression
|
||||||
Il s’agit de supprimer la configuration NGINX pour cette application, puis de recharger la configuration de NGINX :
|
|
||||||
|
Il s’agit de supprimer la configuration NGINX pour cette application, puis de recharger la configuration de NGINX :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
|
@ -10,19 +10,24 @@ routes:
|
||||||
This tutorial aim to help setup NGINX configuration for application packaging.
|
This tutorial aim to help setup NGINX configuration for application packaging.
|
||||||
|
|
||||||
#### NGINX configuration
|
#### NGINX configuration
|
||||||
|
|
||||||
Configuration must be in `conf/nginx.conf`. We must use **FastCGI** or a **proxy_pass** following the application:
|
Configuration must be in `conf/nginx.conf`. We must use **FastCGI** or a **proxy_pass** following the application:
|
||||||
* **FastCGI** is used with PHP applications:
|
* **FastCGI** is used with PHP applications:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
location YNH_EXAMPLE_PATH {
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
alias YNH_WWW_PATH ;
|
location __PATH__/ {
|
||||||
if ($scheme = http) {
|
|
||||||
rewrite ^ https://$server_name$request_uri? permanent;
|
# Path to source
|
||||||
}
|
alias __FINALPATH__/;
|
||||||
|
|
||||||
index index.php;
|
index index.php;
|
||||||
|
|
||||||
try_files $uri $uri/ index.php;
|
try_files $uri $uri/ index.php;
|
||||||
location ~ [^/]\.php(/|$) {
|
location ~ [^/]\.php(/|$) {
|
||||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||||
fastcgi_pass unix:/var/run/php5-fpm.sock;
|
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
|
||||||
|
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
|
@ -36,31 +41,47 @@ location YNH_EXAMPLE_PATH {
|
||||||
```
|
```
|
||||||
|
|
||||||
* **`proxy_pass`** in Python, Node.js, Go and Java applications:
|
* **`proxy_pass`** in Python, Node.js, Go and Java applications:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
location YNH_EXAMPLE_PATH/ {
|
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
|
||||||
rewrite ^YNH_EXAMPLE_PATH$ YNH_EXAMPLE_PATH/ permanent;
|
location __PATH__/ {
|
||||||
proxy_pass http://YNH_EXEMPLE_DOMAIN:YNH_EXAMPLE_PORT/;
|
|
||||||
|
proxy_pass http://127.0.0.1:__PORT__/;
|
||||||
|
proxy_redirect off;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_buffering off;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Host $server_name;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Install script
|
#### Install script
|
||||||
|
|
||||||
We must modify `conf/nginx.conf` file with application arguments. For this, we use generic terms `YNH_EXAMPLE_PATH` that we modify by desired values with `sed` command:
|
We must modify `conf/nginx.conf` file with application arguments. For this, we use generic terms `YNH_EXAMPLE_PATH` that we modify by desired values with `sed` command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
||||||
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
|
||||||
sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
|
sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
|
||||||
```
|
```
|
||||||
We must move that configuration file in NGINX configuration, then reload NGINX configuration:
|
We must move that configuration file in NGINX configuration, then reload NGINX configuration:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
```
|
```
|
||||||
|
|
||||||
If NGINX won't restart, it's possible that this configuration file isn't right.
|
If NGINX won't restart, it's possible that this configuration file isn't right.
|
||||||
|
|
||||||
#### Remove script
|
#### Remove script
|
||||||
|
|
||||||
We must remove NGINX configuration of this application, then reload NGINX configuration:
|
We must remove NGINX configuration of this application, then reload NGINX configuration:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
Loading…
Add table
Reference in a new issue