-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentrypoint.sh
More file actions
529 lines (457 loc) · 18.7 KB
/
entrypoint.sh
File metadata and controls
529 lines (457 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#!/bin/sh
set -eu
#set -euo pipefail
#IFS=$'\n\t'
## Variables
## https://stackoverflow.com/a/32343069/3441436
: "${TZ:=""}" # set timezone, example: "Europe/Berlin"
: "${PHP_ERRORS:="0"}" # set 1 to enable
: "${PHP_MEM_LIMIT:=""}" # set Value in MB, example: 128
: "${PHP_POST_MAX_SIZE:=""}" # set Value in MB, example: 250
: "${PHP_UPLOAD_MAX_FILESIZE:=""}" # set Value in MB, example: 250
: "${PHP_MAX_FILE_UPLOADS:=""}" # set number, example: 20
: "${PHP_MAX_EXECUTION_TIME:=""}" # set execute time
: "${PHP_SET_VARIABLES_ORDER:="0"}" # set variables_order from GPCS to EGPCS, use only for dev!
: "${PHP_SET_OPCACHE_SETTINGS:="0"}" # opcache settings
: "${PHP_FPM_STATUS_PORT:="9001"}" # PHP-FPM Status/Ping Port (default: 9000 but here use 9001)
: "${PHP_FPM_STATUS_PATH:="/php_fpm_status"}" # (default: /status but here use /php_fpm_status)
: "${PHP_FPM_PING_PATH:="/php_fpm_ping"}" # (default: /ping but here use /php_fpm_ping)
: "${ENABLE_PHP_FPM_STATUS:="0"}" # set 1 to enable
: "${CREATE_PHPINFO_FILE:="0"}" # set 1 to enable
: "${CREATE_INDEX_FILE:="0"}" # set 1 to enable
: "${DOCUMENT_ROOT:=""}" # when unset it use default: /var/www/html
: "${ENABLE_APACHE_REWRITE:="0"}" # set 1 to enable
: "${ENABLE_APACHE_ACTIONS:="0"}" # set 1 to enable
: "${ENABLE_APACHE_SSL:="0"}" # set 1 to enable
: "${ENABLE_APACHE_HEADERS:="0"}" # set 1 to enable
: "${ENABLE_APACHE_ALLOWOVERRIDE:="0"}" # set 1 to enable
: "${ENABLE_APACHE_REMOTEIP:="0"}" # set 1 to enable (use this only behind a proxy/loadbalancer)
: "${ENABLE_APACHE_STATUS:="0"}" # set 1 to enable
: "${ENABLE_APACHE_SSL_REDIRECT:="0"}" # set 1 to enable (required enable ssl and rewrite)
: "${APACHE_SERVER_NAME:=""}" # set server name, example: example.com
: "${APACHE_SERVER_ALIAS:=""}" # set server name, example: 'www.example.com *.example.com'
: "${APACHE_SERVER_ADMIN:=""}" # set server admin, example: admin@example.com
: "${APACHE_DOCUMENT_ROOT:="$DOCUMENT_ROOT"}" # when unset it use default: /var/www/html
: "${DISABLE_APACHE_DEFAULTSITES:="0"}" # set 1 to disable default sites (add or mount your own conf in /etc/apache2/sites-enabled)
: "${ENABLE_NGINX_REMOTEIP:="0"}" # set 1 to enable (use this only behind a proxy/loadbalancer)
: "${ENABLE_NGINX_STATUS:="0"}" # set 1 to enable
: "${NGINX_DOCUMENT_ROOT:="$DOCUMENT_ROOT"}" # when unset it use default: /var/www/html
PHP_INI_FILE_NAME="50-php.ini"
lsb_dist="$(. /etc/os-release && echo "$ID")" # get os (example: debian or alpine) - do not change!
## check if php-fpm in this container image exists
PHP_FPM_CONF_DIR_PATH="/usr/local/etc/php-fpm.d"
if [ -d "${PHP_FPM_CONF_DIR_PATH}" -a -f "${PHP_FPM_CONF_DIR_PATH}/www.conf" ]; then
PHP_FPM_IS_EXISTS="1"
else
PHP_FPM_IS_EXISTS="0"
fi
## check if apache in this container image exists
if [ -d "/etc/apache2" -a -f "/etc/apache2/apache2.conf" ]; then
APACHE_IS_EXISTS="1"
else
APACHE_IS_EXISTS="0"
fi
## check if nginx in this container image exists
if [ -d "/etc/nginx" -a -f "/etc/nginx/nginx.conf" ]; then
NGINX_IS_EXISTS="1"
else
NGINX_IS_EXISTS="0"
fi
## print versions
echo ">> print versions ..."
php -v | head -1
if [ "$APACHE_IS_EXISTS" -eq "1" ]; then
#httpd -v
apache2 -v | head -1
fi
if [ "$NGINX_IS_EXISTS" -eq "1" ]; then
nginx -v | head -1
fi
####################################################
##################### PHP ##########################
####################################################
## create php ini file with comment
if [ "$(id -u)" -eq 0 ]; then
echo "; ${PHP_INI_FILE_NAME} create by entrypoint.sh in container image" > /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## set TimeZone
if [ -n "$TZ" ]; then
echo ">> set timezone to ${TZ} ..."
#if [ "$lsb_dist" = "alpine" ]; then apk add --no-cache --virtual .fetch-tmp tzdata; fi
#ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime
cp /usr/share/zoneinfo/${TZ} /etc/localtime
echo ${TZ} > /etc/timezone
echo "date.timezone=${TZ}" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
#if [ "$lsb_dist" = "alpine" ]; then apk del --no-network .fetch-tmp; fi
date
fi
## display PHP error's
if [ "$PHP_ERRORS" -eq "1" ] ; then
echo ">> set display_errors"
echo "display_errors = On" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the memory_limit
if [ -n "$PHP_MEM_LIMIT" ]; then
echo ">> set memory_limit"
echo "memory_limit = ${PHP_MEM_LIMIT}M" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the post_max_size
if [ -n "$PHP_POST_MAX_SIZE" ]; then
echo ">> set post_max_size"
echo "post_max_size = ${PHP_POST_MAX_SIZE}M" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the upload_max_filesize
if [ -n "$PHP_UPLOAD_MAX_FILESIZE" ]; then
echo ">> set upload_max_filesize"
echo "upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}M" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the max_file_uploads
if [ -n "$PHP_MAX_FILE_UPLOADS" ]; then
echo ">> set max_file_uploads"
echo "max_file_uploads = ${PHP_MAX_FILE_UPLOADS}" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the max_execution_time
if [ -n "$PHP_MAX_EXECUTION_TIME" ]; then
echo ">> set max_execution_time"
echo "max_execution_time = ${PHP_MAX_EXECUTION_TIME}" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
## changes the variables_order (add E)
if [ "$PHP_SET_VARIABLES_ORDER" -eq "1" ]; then
echo ">> set variables_order=EGPCS"
echo "variables_order = EGPCS" >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
fi
# OPCACHE Settings
if [ "$PHP_SET_OPCACHE_SETTINGS" -eq "1" ]; then
echo ">> set opcache settings"
cat > /usr/local/etc/php/conf.d/55-opcache.ini <<'EOF'
; https://www.php.net/manual/en/opcache.configuration.php
[opcache]
opcache.enable=1
;opcache.enable_cli=0
opcache.memory_consumption=192
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.max_wasted_percentage=10
opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.save_comments=1
EOF
fi
####################################################
##################### PHP-FPM ######################
####################################################
# Status/Ping
if [ "$PHP_FPM_IS_EXISTS" -eq "1" -a "$ENABLE_PHP_FPM_STATUS" -eq "1" ]; then
echo ">> enabling php-fpm status!"
PHP_FPM_PING_RESPONSE="pong"
cat > ${PHP_FPM_CONF_DIR_PATH}/y-status.conf <<EOF
[www]
; status page
pm.status_path = ${PHP_FPM_STATUS_PATH}
pm.status_listen = ${PHP_FPM_STATUS_PORT}
; ping (healtcheck)
ping.path = ${PHP_FPM_PING_PATH}
;ping.response = ${PHP_FPM_PING_RESPONSE}
EOF
echo ">> ... and create php-fpm-healthcheck.sh"
cat > /usr/local/bin/php-fpm-healthcheck.sh <<EOF
#!/bin/sh
# required: fcgi (alpine) or libfcgi-bin (debian)
SCRIPT_NAME="${PHP_FPM_PING_PATH}" SCRIPT_FILENAME="${PHP_FPM_PING_PATH}" REQUEST_METHOD=GET cgi-fcgi -bind -connect "127.0.0.1:${PHP_FPM_STATUS_PORT}" | grep ${PHP_FPM_PING_RESPONSE}
EOF
chmod +x /usr/local/bin/php-fpm-healthcheck.sh
fi
# Settings (Log, ...)
if [ "$PHP_FPM_IS_EXISTS" -eq "1" ]; then
cat > ${PHP_FPM_CONF_DIR_PATH}/y-settings.conf <<'EOF'
[www]
access.format = "%R - %u %t \"%m %r%Q%q\" %s"
EOF
fi
####################################################
############ for dev and testing ###################
####################################################
## create phpinfo-file
if [ "$CREATE_PHPINFO_FILE" -eq "1" -a ! -e "/var/www/html/phpinfo.php" ]; then
echo ">> create phpinfo-file"
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
fi
## create index file
#if [ \( "$NGINX_IS_EXISTS" -eq "1" -o "$APACHE_IS_EXISTS" -eq "1" \) -a "$CREATE_INDEX_FILE" -eq "1" -a ! -e "/var/www/html/index.php" ]; then
if [ "$CREATE_INDEX_FILE" -eq "1" -a ! -e "/var/www/html/index.php" ]; then
echo ">> create index file"
cat > /var/www/html/index.php <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="Docker Image: tobi312/php">
<title>Site</title>
<!--<link rel="stylesheet" href="style.css">-->
</head>
<body>
<h1>Hello!</h1>
<p>
This is a simple website. Time:<br>
<?php
echo date("Y-m-d H:i:s");
?>
</p>
</body>
</html>
EOF
fi
####################################################
#################### APACHE2 #######################
####################################################
## enable apache2 rewrite
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_REWRITE" -eq "1" ]; then
echo ">> enabling rewrite support"
/usr/sbin/a2enmod rewrite
fi
## enable apache2 actions
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_ACTIONS" -eq "1" ]; then
echo ">> enabling actions support"
/usr/sbin/a2enmod actions
fi
## enable apache2 ssl and generating self-sign ssl files
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_SSL" -eq "1" ]; then
echo ">> enabling SSL support"
/usr/sbin/a2ensite default-ssl
/usr/sbin/a2enmod ssl
if [ ! -e "/etc/ssl/private/ssl-cert-snakeoil.key" ] || [ ! -e "/etc/ssl/certs/ssl-cert-snakeoil.pem" ]; then
echo ">> generating self signed cert ; optional: later you can mount a own certs in container"
openssl req -x509 -newkey rsa:4086 -subj "/C=no/ST=none/L=none/O=none/CN=none" -keyout "/etc/ssl/private/ssl-cert-snakeoil.key" -out "/etc/ssl/certs/ssl-cert-snakeoil.pem" -days 3650 -nodes -sha256
fi
fi
## enable apache2 headers
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_HEADERS" -eq "1" ]; then
echo ">> enabling headers support"
/usr/sbin/a2enmod headers
fi
## set AllowOverride to all
#if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_ALLOWOVERRIDE" == "1" ]; then
# echo ">> set AllowOverride form none to all"
# ## diff -uNr /etc/apache2/apache2.conf /etc/apache2/apache2.conf.txt > /etc/apache2/apache2.conf.diff
#
# cat > /etc/apache2/apache2.conf.diff <<EOF
#--- /etc/apache2/apache2.conf 2016-12-06 17:12:19.000000000 +0100
#+++ /etc/apache2/apache2.conf.txt 2016-12-06 18:28:08.000000000 +0100
#@@ -162,8 +162,8 @@
# </Directory>
#
# <Directory /var/www/>
#- Options Indexes FollowSymLinks
#- AllowOverride None
#+ Options FollowSymLinks
#+ AllowOverride all
# Require all granted
# </Directory>
#
#
#EOF
#
# patch /etc/apache2/apache2.conf < /etc/apache2/apache2.conf.diff
#fi
## set AllowOverride to all
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_ALLOWOVERRIDE" -eq "1" ]; then
echo ">> set AllowOverride form none to all"
sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride all/' /etc/apache2/apache2.conf
sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/Options Indexes FollowSymLinks/Options FollowSymLinks/' /etc/apache2/apache2.conf
fi
## enable remote ip (X-Forwarded-For), use this only behind a proxy/loadbalancer!
## https://gist.github.com/patrocle/43f688e8cfef1a48c66f22825e9e0678
## https://www.globo.tech/learning-center/x-forwarded-for-ip-apache-web-server/
## https://www.digitalocean.com/community/questions/get-client-public-ip-on-apache-server-used-behind-load-balancer
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_REMOTEIP" -eq "1" ]; then
echo ">> enabling remoteip support, use this only behind a proxy!"
cat > /etc/apache2/conf-available/remoteip.conf <<EOF
<IfModule mod_remoteip.c>
RemoteIPHeader X-Forwarded-For
</IfModule>
EOF
/usr/sbin/a2enmod remoteip
/usr/sbin/a2enconf remoteip
sed -i -e 's/LogFormat "%h /LogFormat "%a (%{X-Forwarded-For}i) /g' /etc/apache2/apache2.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_STATUS" -eq "1" ]; then
echo ">> enabling apache status!"
[ -d "/etc/apache2/docker" ] || mkdir /etc/apache2/docker
cat > /etc/apache2/docker/status.conf <<EOF
<IfModule mod_status.c>
#ExtendedStatus on
<Location /server-status>
SetHandler server-status
Order deny,allow
Require all denied
Require local
Require ip 10.0.0.0/8
Require ip 172.16.0.0/12
Require ip 192.168.0.0/16
Require ip fd00::/8
</Location>
</IfModule>
EOF
/usr/sbin/a2enmod status
sed -i "/^ \ \ \ \ \ \ \ Include docker\/status.conf/d" /etc/apache2/sites-available/000-default.conf
sed -i "/#Include conf-available/a \ \ \ \ \ \ \ \ Include docker/status.conf" /etc/apache2/sites-available/000-default.conf
sed -i "/^ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Include docker\/status.conf/d" /etc/apache2/sites-available/default-ssl.conf
sed -i "/#Include conf-available/a \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Include docker/status.conf" /etc/apache2/sites-available/default-ssl.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$ENABLE_APACHE_SSL_REDIRECT" -eq "1" ]; then
echo ">> enabling ssl redirect! (required enable ssl and rewrite)"
[ -d "/etc/apache2/docker" ] || mkdir /etc/apache2/docker
cat > /etc/apache2/docker/redirect_http_to_https.conf <<EOF
<IfModule mod_ssl.c>
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/.well-known/
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
#Redirect permanent / https://%{HTTP_HOST}/
</IfModule>
EOF
sed -i "/^ \ \ \ \ \ \ \ Include docker\/redirect_http_to_https.conf/d" /etc/apache2/sites-available/000-default.conf
sed -i "/#Include conf-available/a \ \ \ \ \ \ \ \ Include docker\/redirect_http_to_https.conf" /etc/apache2/sites-available/000-default.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a -n "$APACHE_SERVER_NAME" ]; then
#APACHE_SERVER_NAME=$(hostname) ## only for debug
echo ">> set ServerName to ${APACHE_SERVER_NAME}"
sed -i "s/#ServerName .*/ServerName ${APACHE_SERVER_NAME}/" /etc/apache2/sites-available/000-default.conf
sed -i "/^ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ServerName /d" /etc/apache2/sites-available/default-ssl.conf
sed -i "/ServerAdmin /i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ServerName ${APACHE_SERVER_NAME}" /etc/apache2/sites-available/default-ssl.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a -n "$APACHE_SERVER_ALIAS" ]; then
echo ">> set ServerAlias to ${APACHE_SERVER_ALIAS}"
sed -i "/^ \ \ \ \ \ \ \ ServerAlias /d" /etc/apache2/sites-available/000-default.conf
#sed -i "/ServerName .*/a \ \ \ \ \ \ \ \ ServerAlias ${APACHE_SERVER_ALIAS}" /etc/apache2/sites-available/000-default.conf
sed -i "/ServerAdmin /i \ \ \ \ \ \ \ \ ServerAlias ${APACHE_SERVER_ALIAS}" /etc/apache2/sites-available/000-default.conf
sed -i "/^ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ServerAlias /d" /etc/apache2/sites-available/default-ssl.conf
#sed -i "/ServerName .*/a \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ServerAlias ${APACHE_SERVER_ALIAS}" /etc/apache2/sites-available/default-ssl.conf
sed -i "/ServerAdmin /i \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ServerAlias ${APACHE_SERVER_ALIAS}" /etc/apache2/sites-available/default-ssl.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a -n "$APACHE_SERVER_ADMIN" ]; then
echo ">> set ServerAdmin to ${APACHE_SERVER_ADMIN}"
sed -i "s/ServerAdmin .*/ServerAdmin ${APACHE_SERVER_ADMIN}/" /etc/apache2/sites-available/000-default.conf
sed -i "s/ServerAdmin .*/ServerAdmin ${APACHE_SERVER_ADMIN}/" /etc/apache2/sites-available/default-ssl.conf
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a "$DISABLE_APACHE_DEFAULTSITES" -eq "1" ]; then
echo ">> disable default sites (add or mount your own conf in /etc/apache2/sites-enabled)"
if [ -f "/etc/apache2/sites-available/000-default.conf" ]; then
/usr/sbin/a2dissite 000-default
fi
if [ -f "/etc/apache2/sites-available/default-ssl.conf" ]; then
/usr/sbin/a2dissite default-ssl
fi
fi
if [ "$APACHE_IS_EXISTS" -eq "1" -a -n "$APACHE_DOCUMENT_ROOT" ]; then
echo ">> setting Apache root to: ${APACHE_DOCUMENT_ROOT}"
find "/etc/apache2/sites-available" -type f -name "*.conf" -print | while read -r f; do
sed -ri "s#^(\s*DocumentRoot\s+)/var/www/html#\1${APACHE_DOCUMENT_ROOT}#g" "$f"
done
fi
####################################################
##################### NGINX ########################
####################################################
NGINX_CONF_FILE="/etc/nginx/conf.d/default.conf"
if [ "$NGINX_IS_EXISTS" -eq "1" -a "$ENABLE_NGINX_STATUS" -eq "1" ]; then
echo ">> enabling nginx status!"
sed -i '/##REPLACE_WITH_NGINXSTATUS_CONFIG##/{
r /dev/stdin
d
}' "${NGINX_CONF_FILE}" <<EOF
# nginx status
location = /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow ::1;
allow fd00::/8;
deny all;
}
# nginx ping
location = /nginx_ping {
add_header Content-Type text/plain;
return 200 'pong';
access_log off;
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow ::1;
allow fd00::/8;
deny all;
}
EOF
fi
if [ "$NGINX_IS_EXISTS" -eq "1" -a "$ENABLE_PHP_FPM_STATUS" -eq "1" ]; then
echo ">> enabling php-fpm status in nginx!"
PHP_FPM_STATUS_LOCATIONNAME=${PHP_FPM_STATUS_PATH#/}
PHP_FPM_PING_LOCATIONNAME=${PHP_FPM_PING_PATH#/}
sed -i '/##REPLACE_WITH_PHPFPMSTATUS_CONFIG##/{
r /dev/stdin
d
}' "${NGINX_CONF_FILE}" <<EOF
# php-fpm status/ping
location ~ ^/(${PHP_FPM_STATUS_LOCATIONNAME}|${PHP_FPM_PING_LOCATIONNAME})\$ {
fastcgi_pass 127.0.0.1:${PHP_FPM_STATUS_PORT};
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
access_log off;
allow 127.0.0.1;
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
allow ::1;
allow fd00::/8;
deny all;
}
EOF
fi
if [ "$NGINX_IS_EXISTS" -eq "1" -a "$ENABLE_NGINX_REMOTEIP" -eq "1" ]; then
# https://nginx.org/en/docs/http/ngx_http_realip_module.html
echo ">> enabling remoteip support, use this only behind a proxy!"
sed -i '/##REPLACE_WITH_REMOTEIP_CONFIG##/{
r /dev/stdin
d
}' "${NGINX_CONF_FILE}" <<'EOF'
# enable ONLY behind PROXY (Traefik, other NGINX, Caddy, lighttpd, K8s Ingress, ...) (ngx_http_realip_module)
set_real_ip_from 172.16.0.0/12;
set_real_ip_from fd00::/8;
##REPLACE_WITH_MORE_REAL_IP##
real_ip_header X-Forwarded-For;
#real_ip_recursive on;
EOF
fi
if [ "$NGINX_IS_EXISTS" -eq "1" -a -n "$NGINX_DOCUMENT_ROOT" ]; then
echo ">> setting NGINX root to: ${NGINX_DOCUMENT_ROOT}"
sed -ri "s#^(\s*root\s+).*;#\1${NGINX_DOCUMENT_ROOT};#g" "$NGINX_CONF_FILE"
fi
####################################################
if [ "$(id -u)" -eq 0 ]; then
[ -d "/entrypoint.d/" ] || mkdir /entrypoint.d/
fi
## more entrypoint-files
find "/entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ ! -x "$f" ] ; then
echo ">> $f is not executable! Set +x ..."
chmod +x $f
fi
echo ">> $f is executed ..."
/bin/sh $f
;;
*) echo ">> $f is no *.sh-file!" ;;
esac
done
# exec CMD
echo ">> exec docker CMD"
echo "$@"
exec "$@"