@@ -12,7 +12,11 @@ set -eu
1212: " ${PHP_POST_MAX_SIZE:= " " } " # set Value in MB, example: 250
1313: " ${PHP_UPLOAD_MAX_FILESIZE:= " " } " # set Value in MB, example: 250
1414: " ${PHP_MAX_FILE_UPLOADS:= " " } " # set number, example: 20
15+ : " ${PHP_MAX_EXECUTION_TIME:= " " } " # set time
16+ : " ${PHP_SET_OPCACHE_SETTINGS:= " 0" } " # opcache settings
17+ : " ${PHP_FPM_STATUS_PORT:= " 9001" } " # PHP-FPM Status/Ping Port (default: 9000 but here use 9001)
1518: " ${PHP_FPM_STATUS_PATH:= " /php_fpm_status" } " # (default: /status but here use /php_fpm_status)
19+ : " ${PHP_FPM_PING_PATH:= " /php_fpm_ping" } " # (default: /ping but here use /php_fpm_ping)
1620: " ${ENABLE_PHP_FPM_STATUS:= " 0" } " # set 1 to enable
1721: " ${CREATE_PHPINFO_FILE:= " 0" } " # set 1 to enable
1822: " ${CREATE_INDEX_FILE:= " 0" } " # set 1 to enable
@@ -35,7 +39,8 @@ PHP_INI_FILE_NAME="50-php.ini"
3539lsb_dist=" $( . /etc/os-release && echo " $ID " ) " # get os (example: debian or alpine) - do not change!
3640
3741# # check if php-fpm in this container image exists
38- if [ -d " /usr/local/etc/php-fpm.d" -a -f " /usr/local/etc/php-fpm.d/www.conf" ]; then
42+ PHP_FPM_CONF_DIR_PATH=" /usr/local/etc/php-fpm.d"
43+ if [ -d " ${PHP_FPM_CONF_DIR_PATH} " -a -f " ${PHP_FPM_CONF_DIR_PATH} /www.conf" ]; then
3944 PHP_FPM_IS_EXISTS=" 1"
4045else
4146 PHP_FPM_IS_EXISTS=" 0"
@@ -121,19 +126,51 @@ if [ -n "$PHP_MAX_EXECUTION_TIME" ]; then
121126 echo " max_execution_time = ${PHP_MAX_EXECUTION_TIME} " >> /usr/local/etc/php/conf.d/${PHP_INI_FILE_NAME}
122127fi
123128
129+ # Status/Ping
130+ if [ -f " /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini" -a " $PHP_SET_OPCACHE_SETTINGS " -eq " 1" ]; then
131+ echo " >> set opcache settings"
132+ cat > /usr/local/etc/php/conf.d/55-opcache.ini << 'EOF '
133+ ; https://www.php.net/manual/en/opcache.configuration.php
134+ [opcache]
135+ opcache.enable=1
136+ ;opcache.enable_cli=0
137+ opcache.memory_consumption=192
138+ opcache.interned_strings_buffer=16
139+ opcache.max_accelerated_files=10000
140+ opcache.max_wasted_percentage=10
141+ opcache.validate_timestamps=1
142+ opcache.revalidate_freq=2
143+ opcache.save_comments=1
144+ EOF
145+ fi
146+
124147# ###################################################
125148# #################### PHP-FPM ######################
126149# ###################################################
127150
128- PHP_FPM_CONF_FILE=" /usr/local/etc/php-fpm.d/www.conf"
129-
151+ # Status/Ping
130152if [ " $PHP_FPM_IS_EXISTS " -eq " 1" -a " $ENABLE_PHP_FPM_STATUS " -eq " 1" ]; then
131153 echo " >> enabling php-fpm status!"
132- # echo -e "[www]\npm.status_path = /status\nping.path = /ping" > /usr/local/etc/php-fpm.d/y-status.conf
133- # echo -e "[www]\npm.status_path = ${PHP_FPM_STATUS_PATH}\nping.path = /ping" > /usr/local/etc/php-fpm.d/y-status.conf
134- # sed -i "s|;pm.status_path.*|pm.status_path = /status|g" ${PHP_FPM_CONF_FILE}
135- sed -i " s|;pm.status_path.*|pm.status_path = ${PHP_FPM_STATUS_PATH} |g" ${PHP_FPM_CONF_FILE}
136- sed -i " s|;ping.path.*|ping.path = /ping|g" ${PHP_FPM_CONF_FILE}
154+
155+ cat > ${PHP_FPM_CONF_DIR_PATH} /y-status.conf << EOF
156+ [www]
157+ ; status page (example: http://localhost:${PHP_FPM_STATUS_PORT}${PHP_FPM_STATUS_PATH} ?json&full)
158+ pm.status_path = ${PHP_FPM_STATUS_PATH}
159+ pm.status_listen = ${PHP_FPM_STATUS_PORT}
160+ ; ping (healtcheck)
161+ ping.path = ${PHP_FPM_PING_PATH}
162+ ;ping.response = pong
163+ EOF
164+
165+ fi
166+
167+ # Settings (Log, ...)
168+ if [ " $PHP_FPM_IS_EXISTS " -eq " 1" ]; then
169+ cat > ${PHP_FPM_CONF_DIR_PATH} /y-settings.conf << 'EOF '
170+ [www]
171+ access.format = "%R - %u %t \"%m %r%Q%q\" %s"
172+ EOF
173+
137174fi
138175
139176# ###################################################
@@ -359,20 +396,68 @@ NGINX_CONF_FILE="/etc/nginx/conf.d/default.conf"
359396
360397if [ " $NGINX_IS_EXISTS " -eq " 1" -a " $ENABLE_NGINX_STATUS " -eq " 1" ]; then
361398 echo " >> enabling nginx status!"
362- nginx_status_string=" location /nginx_status {\n stub_status on;\n access_log off;\n allow 127.0.0.1;\n allow ::1;\n allow 10.0.0.0/8;\n allow 172.16.0.0/12;\n allow 192.168.0.0/16;\n deny all;\n }"
363- sed -i " s|##REPLACE_WITH_NGINXSTATUS_CONFIG##|${nginx_status_string} |g" ${NGINX_CONF_FILE}
399+ sed -i ' /##REPLACE_WITH_NGINXSTATUS_CONFIG##/{
400+ r /dev/stdin
401+ d
402+ }' " ${NGINX_CONF_FILE} " << EOF
403+ # nginx status
404+ location /nginx_status {
405+ stub_status on;
406+ access_log off;
407+ allow 127.0.0.1;
408+ allow 10.0.0.0/8;
409+ allow 172.16.0.0/12;
410+ allow 192.168.0.0/16;
411+ allow ::1;
412+ allow fd00::/8;
413+ deny all;
414+ }
415+
416+ # nginx ping
417+ location /nginx_ping {
418+ add_header Content-Type text/plain;
419+ return 200 'pong';
420+ access_log off;
421+ allow 127.0.0.1;
422+ allow 10.0.0.0/8;
423+ allow 172.16.0.0/12;
424+ allow 192.168.0.0/16;
425+ allow ::1;
426+ allow fd00::/8;
427+ deny all;
428+ }
429+ EOF
364430fi
365431
366432if [ " $NGINX_IS_EXISTS " -eq " 1" -a " $ENABLE_PHP_FPM_STATUS " -eq " 1" ]; then
367433 echo " >> enabling php-fpm status in nginx!"
368- php_fpm_status_string=" location ${PHP_FPM_STATUS_PATH} {\n access_log off;\n allow 127.0.0.1;\n allow ::1;\n allow 10.0.0.0/8;\n allow 172.16.0.0/12;\n allow 192.168.0.0/16;\n deny all;\n fastcgi_param SCRIPT_FILENAME \$ document_root\$ fastcgi_script_name;\n include fastcgi_params;\n fastcgi_pass 127.0.0.1:9000;\n }\n\n location /ping {\n access_log off;\n allow 127.0.0.1;\n allow ::1;\n allow 10.0.0.0/8;\n allow 172.16.0.0/12;\n allow 192.168.0.0/16;\n deny all;\n fastcgi_param SCRIPT_FILENAME \$ document_root\$ fastcgi_script_name;\n include fastcgi_params;\n fastcgi_pass 127.0.0.1:9000;\n }" ; \
369- sed -i " s|##REPLACE_WITH_PHPFPMSTATUS_CONFIG##|${php_fpm_status_string} |g" ${NGINX_CONF_FILE}
434+ PHP_FPM_STATUS_LOCATIONNAME=${PHP_FPM_STATUS_PATH#/ }
435+ PHP_FPM_PING_LOCATIONNAME=${PHP_FPM_PING_PATH#/ }
436+ sed -i ' /##REPLACE_WITH_PHPFPMSTATUS_CONFIG##/{
437+ r /dev/stdin
438+ d
439+ }' " ${NGINX_CONF_FILE} " << EOF
440+ # php-fpm status/ping
441+ location ~ ^/(${PHP_FPM_STATUS_LOCATIONNAME} |${PHP_FPM_PING_LOCATIONNAME} )\$ {
442+ fastcgi_pass 127.0.0.1:${PHP_FPM_STATUS_PORT} ;
443+ fastcgi_param SCRIPT_FILENAME \$ document_root\$ fastcgi_script_name;
444+ include fastcgi_params;
445+ access_log off;
446+ allow 127.0.0.1;
447+ allow 10.0.0.0/8;
448+ allow 172.16.0.0/12;
449+ allow 192.168.0.0/16;
450+ allow ::1;
451+ allow fd00::/8;
452+ deny all;
453+ }
454+ EOF
370455fi
371456
372457if [ " $NGINX_IS_EXISTS " -eq " 1" -a " $ENABLE_NGINX_REMOTEIP " -eq " 1" ]; then
373458 # https://nginx.org/en/docs/http/ngx_http_realip_module.html
374459 echo " >> enabling remoteip support, use this only behind a proxy!"
375- nginx_remoteip_string=" set_real_ip_from 172.20 .0.0/8;\n #set_real_ip_from fd00:dead:beef::/48 ;\n set_real_ip_from fd00::/8;\n ##REPLACE_WITH_MORE_REAL_IP##\n real_ip_header X-Forwarded-For;\n #real_ip_recursive on;\n"
460+ nginx_remoteip_string=" set_real_ip_from 172.16 .0.0/12 ;\n set_real_ip_from fd00::/8;\n ##REPLACE_WITH_MORE_REAL_IP##\n real_ip_header X-Forwarded-For;\n #real_ip_recursive on;\n"
376461 sed -i " s|##REPLACE_WITH_REMOTEIP_CONFIG##|${nginx_remoteip_string} |g" ${NGINX_CONF_FILE}
377462fi
378463
0 commit comments