Skip to content

Commit dd6bc0c

Browse files
committed
Subfolder location is now injected (when needed) into default.conf file.
1 parent f92faae commit dd6bc0c

File tree

3 files changed

+14
-58
lines changed

3 files changed

+14
-58
lines changed

docker-entrypoint.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ if [ "${NGINX_GZIP_ENABLE}" = 1 ]; then
244244
cp /templates/gzip.conf /etc/nginx/conf.d/gzip.conf
245245
fi
246246

247-
# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
248-
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
249-
250247
if [ "${NGINX_SUBFOLDER}" != 0 ]; then
251-
# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
252-
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
248+
print "Activating subfolder configuration"
249+
sed -e '/#subfolder/r /templates/subfolder.conf' -i /templates/default.conf;
253250
fi
254251

252+
# shellcheck disable=SC2016 # The envsubst command needs to be executed without variable expansion
253+
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
254+
255255
# Handle robots.txt and sitemap directive
256256
ROBOTS_PATH=${NGINX_DEFAULT_ROOT}/robots.txt
257257
if [ -n "${SITEMAP_URL}" ] && [ -w "${ROBOTS_PATH}" ] ; then

templates/default.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ server {
5858
return 200;
5959
}
6060

61+
#subfolder
62+
6163
location = /favicon.ico {
6264
expires 30d;
6365
# Google cloud cdn needs a Cache-Control: public header.

templates/subfolder.conf

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,10 @@
1-
upstream php {
2-
server ${PHP_HOST}:${PHP_PORT};
1+
location ~ ${NGINX_SUBFOLDER}/(.*) {
2+
try_files /$1 @rewrite;
33
}
44

5-
map $http_x_forwarded_proto $fastcgi_https {
6-
default $https;
7-
http '';
8-
https on;
9-
}
10-
11-
server {
12-
access_log /var/log/nginx/access.log ${NGINX_ACCESS_LOG_FORMAT};
13-
14-
server_name ${NGINX_DEFAULT_SERVER_NAME};
15-
listen ${NGINX_DEFAULT_SERVER_PORT};
16-
17-
root ${NGINX_DEFAULT_ROOT};
18-
index index.php;
19-
20-
include fastcgi.conf;
21-
#hstsheader
22-
#httpsredirect
23-
#securityheaders
24-
25-
include /etc/nginx/conf.d/fragments/*.conf;
26-
27-
# Just return for google gclb healthcheck.
28-
if ($http_user_agent = 'GoogleHC/1.0') {
29-
return 200;
30-
}
31-
32-
location ~ ${NGINX_SUBFOLDER}/(.*) {
33-
try_files /$1 @rewrite;
34-
}
35-
36-
location @rewrite {
37-
rewrite ^ /index.php;
38-
}
39-
40-
location ~ \.php$ {
41-
include fastcgi.conf;
42-
fastcgi_param SCRIPT_FILENAME $request_filename;
43-
fastcgi_pass php;
44-
}
45-
46-
location ${NGINX_SUBFOLDER} {
47-
if ($http_x_forwarded_proto = "https") {
48-
return 301 https://$host$request_uri/;
49-
}
50-
return 301 http://$host$request_uri/;
51-
}
52-
53-
location / {
54-
try_files $uri/ @rewrite;
55-
}
5+
location ${NGINX_SUBFOLDER} {
6+
if ($http_x_forwarded_proto = "https") {
7+
return 301 https://$host$request_uri/;
8+
}
9+
return 301 http://$host$request_uri/;
5610
}

0 commit comments

Comments
 (0)