Skip to content

Commit

Permalink
remove wildcard redirects in favour or whitelisted domains
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Nov 9, 2023
1 parent 82fe71b commit 7599228
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 23 deletions.
48 changes: 45 additions & 3 deletions config/nginx/conf.d/prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ server {
if ($new_uri_msk != "") {
return 301 https://$new_uri_msk;
}
# process the redirects map file
if ($new_uri != "") {
return 301 https://$host$new_uri;
}
Expand All @@ -36,7 +35,6 @@ server {
if ($new_uri_spb != "") {
return 301 https://$new_uri_spb;
}
# process the redirects map file
if ($new_uri != "") {
return 301 https://$host$new_uri;
}
Expand All @@ -59,10 +57,54 @@ server {
if ($new_uri_tula != "") {
return 301 https://$new_uri_tula;
}
# process the redirects map file
if ($new_uri != "") {
return 301 https://$host$new_uri;
}

include bitrix.conf;
}

server {
listen 80;

server_name favor-group.ru www.favor-group.ru;
# process the redirects, regional and global
if ($new_uri_msk != "") {
return 301 https://$new_uri_msk;
}
if ($new_uri != "") {
return 301 https://favor-group.ru$new_uri;
}

return 301 https://favor-group.ru$request_uri;
}

server {
listen 80;
server_name spb.favor-group.ru;

# process the redirects, regional and global
if ($new_uri_spb != "") {
return 301 https://$new_uri_spb;
}
if ($new_uri != "") {
return 301 https://$host$new_uri;
}

return 301 https://$host$request_uri;
}

server {
listen 80;
server_name tula.favor-group.ru;

# process the redirects, regional and global
if ($new_uri_tula != "") {
return 301 https://$new_uri_tula;
}
if ($new_uri != "") {
return 301 https://$host$new_uri;
}

return 301 https://$host$request_uri;
}
36 changes: 16 additions & 20 deletions config/nginx/conf.d/redirects.conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# https www is a special case
server {
listen 80 default_server;
listen 443 ssl http2;
server_name www.favor-group.ru;
ssl_certificate /etc/nginx/letsencrypt/live/favor-group.ru/fullchain.pem;
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem;

# process the redirects map file
# process the redirects, regional and global
if ($new_uri_msk != "") {
return 301 https://$new_uri_msk;
}
if ($new_uri != "") {
return 301 https://$host$new_uri;
return 301 https://favor-group.ru$new_uri;
}

return 301 https://$host$request_uri;
return 301 https://favor-group.ru$request_uri;
}

# www is a separate case, as we want to redirect it directly to the root domain
# without redirecting to www domain with https first
# default servers, returning 404s
server {
listen 80;

server_name www.favor-group.ru;
# process the redirects map file
if ($new_uri != "") {
return 301 https://favor-group.ru$new_uri;
}
listen 80 default_server;

return 301 https://favor-group.ru$request_uri;
return 404;
}

server {
Expand All @@ -29,10 +30,5 @@ server {
ssl_certificate_key /etc/nginx/letsencrypt/live/favor-group.ru/privkey.pem;
ssl_trusted_certificate /etc/nginx/letsencrypt/live/favor-group.ru/chain.pem;

# process the redirects map file
if ($new_uri != "") {
return 301 https://favor-group.ru$new_uri;
}

return 301 https://favor-group.ru$request_uri;
return 404;
}

0 comments on commit 7599228

Please sign in to comment.