Skip to content

refs #65: Refactor redirects #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feature/d8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions templates/catch-all-server.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# This is the default catch all server, that intercept all requests
# not served by others server block declarations.

# We create a map for a valid domains to be redirected.
map $scheme://$host$request_uri $new_domain_uri {
include /etc/nginx/conf.d/redirects[.]map;
## Match redirects, in the following order:
## https://www.example.com/foobar
## www.example.com/test
## /test
map $scheme://$host$request_uri $new_scheme_host_and_uri {
include /etc/nginx/conf.d/redirects[.]map;
}
map $host$request_uri $new_host_and_uri {
include /etc/nginx/conf.d/redirects[.]map;
}
map $request_uri $new_uri {
include /etc/nginx/conf.d/redirects[.]map;
}

server {
Expand All @@ -16,7 +25,13 @@ server {
#hstsheader

# If the URL is a valid redirect URL it will be handled here
if ($new_domain_uri) {
if ($new_scheme_host_and_uri) {
return 301 $new_domain_uri;
}
if ($new_host_and_uri) {
return 301 $new_domain_uri;
}
if ($new_uri) {
return 301 $new_domain_uri;
}

Expand Down
24 changes: 15 additions & 9 deletions templates/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ map $http_x_forwarded_proto $fastcgi_https {
https on;
}

# We should use $host$request_uri to support redirects when nginx is serving multiple domains.
## Match redirects, in the following order:
## https://www.example.com/foobar
## www.example.com/test
## /test
map $scheme://$host$request_uri $new_scheme_host_and_uri {
include /etc/nginx/conf.d/redirects[.]map;
}
map $host$request_uri $new_host_and_uri {
include /etc/nginx/conf.d/redirects[.]map;
}

# We should use $request_uri to support redirects with query parameters.
map $request_uri $new_uri {
include /etc/nginx/conf.d/redirects[.]map;
}
Expand All @@ -23,21 +27,23 @@ include /etc/nginx/conf.d/custom/*.conf;

server {
server_name ${NGINX_DEFAULT_SERVER_NAME};
# Please note that nginx always has a default server.
# In the absence of any server block explicitly marked
# as default_server , nginx will use the first server
# Please note that nginx always has a default server.
# In the absence of any server block explicitly marked
# as default_server , nginx will use the first server
# with a matching listen directive.
# If defaul_server is set, this server will be the
# default, catch all server, regardless of server_name.
listen ${NGINX_DEFAULT_SERVER_PORT} ${DEFAULT_SERVER};

#hstsheader
if ($new_scheme_host_and_uri) {
return 301 $new_domain_uri;
}
if ($new_host_and_uri) {
return 301 $new_host_and_uri;
return 301 $new_domain_uri;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at the work done by @Monska85 in https://github.com/sparkfabrik/docker-php-drupal-nginx/pull/81/files and wondering if it's ok to change this line (43) and line 46 below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think we should update the Readme+Changelog like we did in #81

}

if ($new_uri) {
return 301 $new_uri;
return 301 $new_domain_uri;
}

root ${NGINX_DEFAULT_ROOT};
Expand Down