Skip to content
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

Subfolder location is now injected (when needed) into default.conf file. #119

Open
wants to merge 4 commits 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
13 changes: 8 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,17 @@ if [ "${NGINX_GZIP_ENABLE}" = 1 ]; then
cp /templates/gzip.conf /etc/nginx/conf.d/gzip.conf
fi

# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${DEFAULT_SERVER} ${NGINX_XFRAME_OPTION_VALUE} ${NGINX_HSTS_HEADER} ${NGINX_CSP_HEADER}' < /templates/default.conf > /etc/nginx/conf.d/default.conf

if [ "${NGINX_SUBFOLDER}" != 0 ]; then
# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_XFRAME_OPTION_VALUE} ${NGINX_HSTS_HEADER}' < /templates/subfolder.conf > /etc/nginx/conf.d/default.conf
print "Activating subfolder configuration"
if ! sed -e '/#subfolder/r /templates/subfolder.conf' -i /templates/default.conf; then
echo "Error: Failed to apply subfolder configuration" >&2
exit 1
fi
fi

# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
envsubst '${PHP_HOST} ${PHP_PORT} ${NGINX_ACCESS_LOG_FORMAT} ${NGINX_DEFAULT_SERVER_PORT} ${NGINX_DEFAULT_SERVER_NAME} ${NGINX_DEFAULT_ROOT} ${DEFAULT_SERVER} ${NGINX_SUBFOLDER} ${NGINX_SUBFOLDER_ESCAPED} ${NGINX_XFRAME_OPTION_VALUE} ${NGINX_HSTS_HEADER} ${NGINX_CSP_HEADER}' < /templates/default.conf > /etc/nginx/conf.d/default.conf

# Handle robots.txt and sitemap directive
ROBOTS_PATH=${NGINX_DEFAULT_ROOT}/robots.txt
if [ -n "${SITEMAP_URL}" ] && [ -w "${ROBOTS_PATH}" ] ; then
Expand Down
2 changes: 2 additions & 0 deletions templates/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ server {
return 200;
}

#subfolder

location = /favicon.ico {
expires 30d;
# Google cloud cdn needs a Cache-Control: public header.
Expand Down
53 changes: 0 additions & 53 deletions templates/subfolder.conf
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
upstream php {
server ${PHP_HOST}:${PHP_PORT};
}

map $http_x_forwarded_proto $fastcgi_https {
default $https;
http '';
https on;
}

server {
access_log /var/log/nginx/access.log ${NGINX_ACCESS_LOG_FORMAT};

server_name ${NGINX_DEFAULT_SERVER_NAME};
listen ${NGINX_DEFAULT_SERVER_PORT};

root ${NGINX_DEFAULT_ROOT};
index index.php;

include fastcgi.conf;
#hstsheader
#httpsredirect
#securityheaders

include /etc/nginx/conf.d/fragments/*.conf;

# Just return for google gclb healthcheck.
if ($http_user_agent = 'GoogleHC/1.0') {
return 200;
}

location ~ ${NGINX_SUBFOLDER}/(.*) {
try_files /$1 @rewrite;
}

location @rewrite {
rewrite ^ /index.php;
}

location ~ \.php$ {
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass php;
}

location ${NGINX_SUBFOLDER} {
if ($http_x_forwarded_proto = "https") {
return 301 https://$host$request_uri/;
}
return 301 http://$host$request_uri/;
}

location / {
try_files $uri/ @rewrite;
}
}
Loading