From ac9182d69fdabbdaffd7cde84b7c0485d0482e89 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 25 Jun 2020 21:42:35 +0200 Subject: [PATCH] Move redirect to /yunohost/admin to a separate nginx conf file to allow customizing it more easily --- data/hooks/conf_regen/15-nginx | 5 +++++ data/templates/nginx/redirect_to_admin.conf | 3 +++ data/templates/nginx/yunohost_admin.conf | 12 ------------ 3 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 data/templates/nginx/redirect_to_admin.conf diff --git a/data/hooks/conf_regen/15-nginx b/data/hooks/conf_regen/15-nginx index 4924b6f91..a7574b070 100755 --- a/data/hooks/conf_regen/15-nginx +++ b/data/hooks/conf_regen/15-nginx @@ -26,6 +26,9 @@ do_init_regen() { ynh_render_template "security.conf.inc" "${nginx_conf_dir}/security.conf.inc" ynh_render_template "yunohost_admin.conf" "${nginx_conf_dir}/yunohost_admin.conf" + mkdir -p $nginx_conf_dir/default.d/ + cp "redirect_to_admin.conf" $nginx_conf_dir/default.d/ + # Restart nginx if conf looks good, otherwise display error and exit unhappy nginx -t 2>/dev/null || { nginx -t; exit 1; } systemctl restart nginx || { journalctl --no-pager --lines=10 -u nginx >&2; exit 1; } @@ -77,6 +80,8 @@ do_pre_regen() { done ynh_render_template "yunohost_admin.conf" "${nginx_conf_dir}/yunohost_admin.conf" + mkdir -p $nginx_conf_dir/default.d/ + cp "redirect_to_admin.conf" $nginx_conf_dir/default.d/ # remove old domain conf files conf_files=$(ls -1 /etc/nginx/conf.d \ diff --git a/data/templates/nginx/redirect_to_admin.conf b/data/templates/nginx/redirect_to_admin.conf new file mode 100644 index 000000000..22748daa3 --- /dev/null +++ b/data/templates/nginx/redirect_to_admin.conf @@ -0,0 +1,3 @@ +location / { + return 302 https://$http_host/yunohost/admin; +} diff --git a/data/templates/nginx/yunohost_admin.conf b/data/templates/nginx/yunohost_admin.conf index d405192fc..b6d0b6d97 100644 --- a/data/templates/nginx/yunohost_admin.conf +++ b/data/templates/nginx/yunohost_admin.conf @@ -2,14 +2,6 @@ server { listen 80 default_server; listen [::]:80 default_server; - location / { - return 302 https://$http_host/yunohost/admin; - } - - location /yunohost/admin { - return 301 https://$http_host$request_uri; - } - include /etc/nginx/conf.d/default.d/*.conf; } @@ -25,10 +17,6 @@ server { more_set_headers "Strict-Transport-Security : max-age=63072000; includeSubDomains; preload"; more_set_headers "Referrer-Policy : 'same-origin'"; - location / { - return 302 https://$http_host/yunohost/admin; - } - location /yunohost { # Block crawlers bot if ($http_user_agent ~ (crawl|Googlebot|Slurp|spider|bingbot|tracker|click|parser|spider|facebookexternalhit) ) {