doc/pages/06.contribute/10.packaging_apps/09.nginx/packaging_apps_nginx_conf.md

89 lines
2.5 KiB
Markdown
Raw Normal View History

2020-11-11 11:47:10 +01:00
---
title: NGINX configuration
template: docs
taxonomy:
category: docs
routes:
default: '/packaging_apps_nginx_conf'
2020-11-11 11:47:10 +01:00
---
2020-09-18 19:11:15 +02:00
2020-09-15 13:57:31 +02:00
This tutorial aim to help setup NGINX configuration for application packaging.
2016-01-30 19:41:48 +01:00
2020-09-15 13:57:31 +02:00
#### NGINX configuration
2022-10-17 23:30:42 +02:00
2016-01-30 19:41:48 +01:00
Configuration must be in `conf/nginx.conf`. We must use **FastCGI** or a **proxy_pass** following the application:
* **FastCGI** is used with PHP applications:
2022-10-17 23:30:42 +02:00
```nginx
2022-10-17 23:30:42 +02:00
#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
location __PATH__/ {
# Path to source
alias __FINALPATH__/;
2021-02-07 17:21:51 +01:00
index index.php;
2022-10-17 23:30:42 +02:00
2021-02-07 17:21:51 +01:00
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
2022-10-17 23:30:42 +02:00
fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock;
2021-02-07 17:21:51 +01:00
fastcgi_index index.php;
include fastcgi_params;
2022-10-17 23:30:42 +02:00
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param PATH_INFO $fastcgi_path_info;
2021-02-07 17:21:51 +01:00
fastcgi_param SCRIPT_FILENAME $request_filename;
}
2016-01-30 19:41:48 +01:00
2021-02-07 17:21:51 +01:00
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
2016-01-30 19:41:48 +01:00
}
```
* **`proxy_pass`** in Python, Node.js, Go and Java applications:
2022-10-17 23:30:42 +02:00
```nginx
2022-10-17 23:30:42 +02:00
#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";
2016-01-30 19:41:48 +01:00
}
```
#### Install script
2022-10-17 23:30:42 +02:00
2016-01-30 19:41:48 +01:00
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:
2022-10-17 23:30:42 +02:00
2016-01-30 19:41:48 +01:00
```bash
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
2022-11-30 13:50:50 +01:00
sed -i "s@YNH_EXAMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
2016-01-30 19:41:48 +01:00
```
2020-09-15 13:57:31 +02:00
We must move that configuration file in NGINX configuration, then reload NGINX configuration:
2022-10-17 23:30:42 +02:00
2016-01-30 19:41:48 +01:00
```bash
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
```
2022-10-17 23:30:42 +02:00
2020-09-15 13:57:31 +02:00
If NGINX won't restart, it's possible that this configuration file isn't right.
2016-01-30 19:41:48 +01:00
#### Remove script
2022-10-17 23:30:42 +02:00
2020-09-15 13:57:31 +02:00
We must remove NGINX configuration of this application, then reload NGINX configuration:
2022-10-17 23:30:42 +02:00
2016-01-30 19:41:48 +01:00
```bash
rm -f /etc/nginx/conf.d/$domain.d/$app.conf
sudo service nginx reload
```