Skip to content

Commit 6a663f9

Browse files
committed
changes
opcache, php-fpm status/ping (include port changes for php-fpm), nginx status/ping, bugfix, fpm log settings, IPs
1 parent d786ee7 commit 6a663f9

9 files changed

Lines changed: 119 additions & 29 deletions

alpine.fpm.wsc.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ RUN \
5454
php -m
5555

5656
# opcache config
57-
COPY conf/php_70-opcache.ini /usr/local/etc/php/conf.d/70-opcache.ini
57+
#COPY conf/php_55-opcache.ini /usr/local/etc/php/conf.d/55-opcache.ini

alpine.fpm_nginx.extended.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ENV ENABLE_NGINX_STATUS=1 \
1212
ENABLE_PHP_FPM_STATUS=1 \
1313
WWW_USER=www-data \
1414
NGINX_EXPORTER="--nginx.scrape-uri='http://localhost/nginx_status' --web.listen-address=':9113' --web.telemetry-path='/metrics' --no-nginx.ssl-verify" \
15-
PHP_FPM_EXPORTER="server --phpfpm.scrape-uri='tcp://127.0.0.1:9000/php_fpm_status' --web.listen-address=':9253' --web.telemetry-path='/metrics' --log.level=info --phpfpm.fix-process-count=false"
15+
PHP_FPM_EXPORTER="--phpfpm.scrape-uri='tcp://127.0.0.1:9001/php_fpm_status' --web.listen-address=':9253' --web.telemetry-path='/metrics' --log.level=info --phpfpm.fix-process-count=false"
1616

1717
# install tools
1818
#RUN apk --no-cache add \
@@ -80,7 +80,7 @@ RUN \
8080
{ \
8181
echo ''; \
8282
echo '[program:exporter-phpfpm]'; \
83-
echo 'command=sh -c "sleep 5 && /usr/local/bin/php-fpm-exporter %(ENV_PHP_FPM_EXPORTER)s"'; \
83+
echo 'command=sh -c "sleep 5 && /usr/local/bin/php-fpm-exporter server %(ENV_PHP_FPM_EXPORTER)s"'; \
8484
echo "user=%(ENV_WWW_USER)s"; \
8585
echo 'stdout_logfile=/dev/stdout'; \
8686
echo 'stdout_logfile_maxbytes=0'; \

alpine.fpm_nginx.extended.git.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ENV ENABLE_NGINX_STATUS=1 \
5151
ENABLE_PHP_FPM_STATUS=1 \
5252
WWW_USER=www-data \
5353
NGINX_EXPORTER="--nginx.scrape-uri='http://localhost/nginx_status' --web.listen-address=':9113' --web.telemetry-path='/metrics' --no-nginx.ssl-verify" \
54-
PHP_FPM_EXPORTER="server --phpfpm.scrape-uri='tcp://127.0.0.1:9000/php_fpm_status' --web.listen-address=':9253' --web.telemetry-path='/metrics' --log.level=info --phpfpm.fix-process-count=false"
54+
PHP_FPM_EXPORTER="--phpfpm.scrape-uri='tcp://127.0.0.1:9001/php_fpm_status' --web.listen-address=':9253' --web.telemetry-path='/metrics' --log.level=info --phpfpm.fix-process-count=false"
5555

5656
# install tools
5757
#RUN apk --no-cache add \
@@ -82,7 +82,7 @@ RUN \
8282
{ \
8383
echo ''; \
8484
echo '[program:exporter-phpfpm]'; \
85-
echo 'command=sh -c "sleep 5 && /usr/local/bin/php-fpm-exporter %(ENV_PHP_FPM_EXPORTER)s"'; \
85+
echo 'command=sh -c "sleep 5 && /usr/local/bin/php-fpm-exporter server %(ENV_PHP_FPM_EXPORTER)s"'; \
8686
echo "user=%(ENV_WWW_USER)s"; \
8787
echo 'stdout_logfile=/dev/stdout'; \
8888
echo 'stdout_logfile_maxbytes=0'; \

alpine.fpm_nginx.slim.Dockerfile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,22 @@ RUN apk --no-cache add \
108108
} > /etc/nginx/nginx.conf \
109109
; \
110110
{ \
111+
echo '##REPLACE_WITH_REMOTEIP_CONFIG##'; \
112+
echo ''; \
111113
echo 'server {'; \
112114
echo ' listen 80 default_server;'; \
113115
echo ' listen [::]:80 default_server;'; \
114116
echo ' #server_name _;'; \
115117
echo ' '; \
116-
echo ' ##REPLACE_WITH_REMOTEIP_CONFIG##'; \
117-
echo ' '; \
118-
echo ' #client_max_body_size 64M;'; \
119-
echo ' '; \
120-
echo ' ##REPLACE_WITH_NGINXSTATUS_CONFIG##'; \
121-
echo ' '; \
122-
echo ' ##REPLACE_WITH_PHPFPMSTATUS_CONFIG##'; \
118+
echo ' # disable any limits to avoid HTTP 413 for large image uploads'; \
119+
echo ' client_max_body_size 0;'; \
123120
echo ' '; \
124121
echo ' root /var/www/html;'; \
125-
echo ' index index.html index.htm index.php;'; \
122+
echo ' index index.php index.html;'; \
126123
echo ' '; \
127124
echo ' location / {'; \
128125
echo ' try_files $uri $uri/ =404;'; \
126+
echo ' #try_files $uri $uri/ /index.php?$query_string;'; \
129127
echo ' }'; \
130128
echo ' '; \
131129
echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000'; \
@@ -140,6 +138,13 @@ RUN apk --no-cache add \
140138
echo ' include fastcgi_params;'; \
141139
echo ' }'; \
142140
echo ' '; \
141+
echo ' ##REPLACE_WITH_NGINXSTATUS_CONFIG##'; \
142+
echo ' '; \
143+
echo ' ##REPLACE_WITH_PHPFPMSTATUS_CONFIG##'; \
144+
echo ' '; \
145+
echo ' location ~ /\.ht {'; \
146+
echo ' deny all;'; \
147+
echo ' }'; \
143148
echo ' '; \
144149
echo ' location = /favicon.ico { log_not_found off; access_log off; }'; \
145150
echo ' location = /robots.txt { log_not_found off; access_log off; }'; \

alpine.fpm_nginx.wsc.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ RUN \
5454
php -m
5555

5656
# opcache config
57-
COPY conf/php_70-opcache.ini /usr/local/etc/php/conf.d/70-opcache.ini
57+
#COPY conf/php_55-opcache.ini /usr/local/etc/php/conf.d/55-opcache.ini

debian.apache.wsc.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ RUN \
5656
php -m
5757

5858
# opcache config
59-
COPY conf/php_70-opcache.ini /usr/local/etc/php/conf.d/70-opcache.ini
59+
#COPY conf/php_55-opcache.ini /usr/local/etc/php/conf.d/55-opcache.ini

debian.fpm.wsc.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ RUN \
5656
php -m
5757

5858
# opcache config
59-
COPY conf/php_70-opcache.ini /usr/local/etc/php/conf.d/70-opcache.ini
59+
#COPY conf/php_55-opcache.ini /usr/local/etc/php/conf.d/55-opcache.ini

entrypoint.sh

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
3539
lsb_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"
4045
else
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}
122127
fi
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
130152
if [ "$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+
137174
fi
138175

139176
####################################################
@@ -359,20 +396,68 @@ NGINX_CONF_FILE="/etc/nginx/conf.d/default.conf"
359396

360397
if [ "$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
364430
fi
365431

366432
if [ "$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
370455
fi
371456

372457
if [ "$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}
377462
fi
378463

0 commit comments

Comments
 (0)