diff --git a/conf/example-custom-nginx-config.conf b/conf/example-custom-nginx-config.conf new file mode 100644 index 0000000..0d72ff4 --- /dev/null +++ b/conf/example-custom-nginx-config.conf @@ -0,0 +1,2 @@ +# Common parameter to increase upload size limit in conjunction with dedicated PHP-FPM file +#client_max_body_size 1G; \ No newline at end of file diff --git a/conf/nginx-php.conf b/conf/nginx-php.conf new file mode 100644 index 0000000..f68f202 --- /dev/null +++ b/conf/nginx-php.conf @@ -0,0 +1,10 @@ +# Execute and serve PHP files +location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.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; +} diff --git a/conf/nginx_no_php.conf b/conf/nginx.conf similarity index 84% rename from conf/nginx_no_php.conf rename to conf/nginx.conf index a80930c..9f696ae 100644 --- a/conf/nginx_no_php.conf +++ b/conf/nginx.conf @@ -4,9 +4,6 @@ location __PATH__/ { # Path to source alias __INSTALL_DIR__/www/; - # Common parameter to increase upload size limit in conjunction with dedicated PHP-FPM file - client_max_body_size 500M; - # Default indexes and catch-all index index.html index.php; try_files $uri $uri/ __PATH__/index.php?$args; @@ -28,6 +25,8 @@ location __PATH__/ { deny all; } + include conf.d/__DOMAIN__.d/__APP__.d/*.conf; + # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/nginx_with_php.conf b/conf/nginx_with_php.conf deleted file mode 100644 index 7f5752e..0000000 --- a/conf/nginx_with_php.conf +++ /dev/null @@ -1,44 +0,0 @@ -#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; -location __PATH__/ { - - # Path to source - alias __INSTALL_DIR__/www/; - - # Common parameter to increase upload size limit in conjunction with dedicated PHP-FPM file - client_max_body_size 500M; - - # Default indexes and catch-all - index index.html index.php; - try_files $uri $uri/ __PATH__/index.php?$args; - - # Prevent useless logs - location = __PATH__/favicon.ico { - log_not_found off; - access_log off; - } - - location = __PATH__/robots.txt { - allow all; - log_not_found off; - access_log off; - } - - # Deny access to hidden files and directories - location ~ ^__PATH__/(.+/|)\.(?!well-known\/) { - deny all; - } - - # Execute and serve PHP files - location ~ [^/]\.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(/.*)$; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.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. - include conf.d/yunohost_panel.conf.inc; -} diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md index de48a9d..f24ccce 100644 --- a/doc/DESCRIPTION.md +++ b/doc/DESCRIPTION.md @@ -5,3 +5,5 @@ It can also create a MySQL database - which will be backed up and restored with PHP-FPM version can also be selected among `none`, `7.4`, `8.0`, `8.1` and `8.2`. **Once installed, go to the chosen URL to know the user, domain and port you will have to use for the SFTP access.** The password is one you chosen during the installation. Under the Web directory, you will see a `www` folder which contains the public files served by this app. You can put all the files of your custom Web application inside. + +If you want to add customized nginx configuration, put it in `/etc/nginx/conf.d/YOUR_DOMAIN.d/my_webapp.d/WHATEVER_NAME.conf` (ensure that the file has the `.conf` extension, and change `my_webapp.d` to `my_webapp__xx.d` if you want to change the configuration of the second or more installation of my_webapp). diff --git a/doc/DESCRIPTION_fr.md b/doc/DESCRIPTION_fr.md index 2bf7f20..956bd4a 100644 --- a/doc/DESCRIPTION_fr.md +++ b/doc/DESCRIPTION_fr.md @@ -5,3 +5,5 @@ Elle peut également créer une base de données MySQL - qui sera sauvegardée e La version de PHP-FPM peut aussi être choisie, parmi `none`, `7.4`, `8.0`, `8.1` et `8.2`. **Une fois installé, rendez-vous sur l'URL choisie pour connaître l'utilisateur, le domaine et le port que vous devrez utiliser pour l'accès SFTP.** Le mot de passe est celui que vous avez choisi lors de l'installation. Sous le répertoire Web, vous verrez un dossier `www` qui contient les fichiers publics servis par cette application. Vous pouvez mettre tous les fichiers de votre application Web personnalisée à l'intérieur. + +Si vous voulez ajouter une configuration personnalisée de nginx, mettez-la dans `/etc/nginx/conf.d/votre_domaine.d/my_webapp.d/WHATEVER_NAME.conf` (assurez-vous que le fichier a l'extension `.conf`, et changez `my_webapp.d` en `my_webapp__xx.d` si vous voulez changer la configuration de la deuxième installation ou plus de my_webapp). diff --git a/scripts/backup b/scripts/backup index 2d2ea7a..40b562e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -34,6 +34,7 @@ ynh_backup --src_path="$install_dir" #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.d" #================================================= # BACKUP THE PHP-FPM CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index a430715..4433872 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,6 +9,21 @@ source _common.sh source /usr/share/yunohost/helpers +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=5 + +# Backup the current version of the app +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.d" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} + #================================================= # ACTIVATE MAINTENANCE MODE #================================================= @@ -25,14 +40,7 @@ ynh_maintenance_mode_ON ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Prepare nginx.conf -if [ $phpversion != "none" ] -then - cp ../conf/nginx{_with_php,}.conf -else - cp ../conf/nginx{_no_php,}.conf -fi +nginx_extra_conf_dir=/etc/nginx/conf.d/$old_domain.d/$app.d # Change the path in the NGINX config file if [ $change_path -eq 1 ] @@ -53,10 +61,19 @@ if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + ynh_delete_file_checksum --file="$nginx_extra_conf_dir/php.conf" + + path_url="$new_path" + domain="$old_domain" + ynh_remove_nginx_config + + domain="$new_domain" + ynh_add_nginx_config + + mv $nginx_extra_conf_dir /etc/nginx/conf.d/$new_domain.d/$app.d # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.d/php.conf" fi #================================================= diff --git a/scripts/config b/scripts/config index 3f3d88c..7763f7c 100644 --- a/scripts/config +++ b/scripts/config @@ -119,11 +119,14 @@ ynh_app_config_apply() { # ^ ynh_add_config replaces __PHPVERSION__ by __PHP_YNH_VERSION__... ynh_app_setting_set --app=$app --key=phpversion --value="$phpversion" + nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d" + mkdir -p "$nginx_extra_conf_dir" if [ "$phpversion" == "none" ] then - cp ../conf/nginx{_no_php,}.conf + ynh_delete_file_checksum --file="$nginx_extra_conf_dir/php.conf" + ynh_secure_remove --file="$nginx_extra_conf_dir/php.conf" else - cp ../conf/nginx{_with_php,}.conf + ynh_add_config --template="nginx-php.conf" --destination="$nginx_extra_conf_dir/php.conf" ynh_install_app_dependencies "php${phpversion}-fpm" ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --phpversion=$phpversion # ^ the helper takes care of ynh_app_setting_set the phpversion diff --git a/scripts/install b/scripts/install index ed2d9f2..8280d3d 100644 --- a/scripts/install +++ b/scripts/install @@ -58,17 +58,19 @@ fi #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=2 -# Prepare nginx.conf +nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d" +mkdir -p "$nginx_extra_conf_dir" + +# Prepare nginx extra conf if [ $phpversion != "none" ] then - cp ../conf/nginx{_with_php,}.conf + ynh_add_config --template="nginx-php.conf" --destination="$nginx_extra_conf_dir/php.conf" YNH_PHP_VERSION="$phpversion" -else - cp ../conf/nginx{_no_php,}.conf fi # Create a dedicated NGINX config ynh_add_nginx_config +ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf" #================================================= # CREATE DEDICATED USER diff --git a/scripts/remove b/scripts/remove index a037124..962cf23 100644 --- a/scripts/remove +++ b/scripts/remove @@ -39,6 +39,7 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.d" #================================================= # REMOVE PHP-FPM CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 3759d0a..68e97f0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -23,6 +23,7 @@ password=$(ynh_app_setting_get --app=$app --key=password) #================================================= ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.d/" #================================================= # RESTORE THE MYSQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index a8d9a3e..f517cc3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -79,16 +79,20 @@ ynh_maintenance_mode_ON ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 # Prepare nginx.conf +nginx_extra_conf_dir="/etc/nginx/conf.d/$domain.d/$app.d" + +mkdir -p "$nginx_extra_conf_dir" + +# Prepare nginx extra conf if [ $phpversion != "none" ] then - cp ../conf/nginx{_with_php,}.conf + ynh_add_config --template="nginx-php.conf" --destination="$nginx_extra_conf_dir/php.conf" YNH_PHP_VERSION="$phpversion" -else - cp ../conf/nginx{_no_php,}.conf fi # Create a dedicated NGINX config ynh_add_nginx_config +ynh_add_config --template="example-custom-nginx-config.conf" --destination="$nginx_extra_conf_dir/sample.conf" #================================================= # CREATE DEDICATED USER