Migrate to PHP-FPM for all Web images

This commit is contained in:
Alexey Pustovalov
2025-01-13 19:24:39 +09:00
parent f793ad94ac
commit 0ad215b50d
131 changed files with 3919 additions and 1852 deletions

View File

@ -18,11 +18,19 @@ fi
# Default timezone for web interface
: ${PHP_TZ:="Europe/Riga"}
# Default user settings
: ${DAEMON_USER:="apache"}
: ${DAEMON_GROUP:="apache"}
# Default directories
# Web interface www-root directory
ZABBIX_WWW_ROOT="/usr/share/zabbix"
# Apache main configuration file
HTTPD_CONF_FILE="/etc/httpd/conf/httpd.conf"
# Apache additional configuration files directory
APACHE_SITES_DIR="/etc/httpd/conf.d"
# Directory with SSL certificate files for Apache
APACHE_SSL_CONFIG_DIR="/etc/ssl/apache2"
# PHP-FPM configuration file
PHP_CONFIG_FILE="/etc/php-fpm.d/zabbix.conf"
# usage: file_env VAR [DEFAULT]
# as example: file_env 'MYSQL_PASSWORD' 'zabbix'
@ -131,7 +139,12 @@ check_db_connect() {
}
prepare_web_server() {
APACHE_SITES_DIR=/etc/httpd/conf.d
if [ "$(id -u)" == '0' ]; then
export APACHE_RUN_USER=${DAEMON_USER}
else
export APACHE_RUN_USER=$(id -n -u)
fi
export APACHE_RUN_GROUP=${DAEMON_GROUP}
echo "** Adding Zabbix virtual host (HTTP)"
if [ -f "$ZABBIX_CONF_DIR/apache.conf" ]; then
@ -140,7 +153,7 @@ prepare_web_server() {
echo "**** Impossible to enable HTTP virtual host"
fi
if [ -f "/etc/ssl/apache2/ssl.crt" ] && [ -f "/etc/ssl/apache2/ssl.key" ]; then
if [ -f "$APACHE_SSL_CONFIG_DIR/ssl.crt" ] && [ -f "$APACHE_SSL_CONFIG_DIR/ssl.key" ]; then
echo "** Adding Zabbix virtual host (HTTPS)"
if [ -f "$ZABBIX_CONF_DIR/apache_ssl.conf" ]; then
ln -sfT "$ZABBIX_CONF_DIR/apache_ssl.conf" "$APACHE_SITES_DIR/zabbix_ssl.conf"
@ -150,12 +163,28 @@ prepare_web_server() {
else
echo "**** Impossible to enable SSL support for Apache2. Certificates are missed."
fi
export HTTP_INDEX_FILE=${HTTP_INDEX_FILE:="index.php"}
: ${ENABLE_WEB_ACCESS_LOG:="true"}
export APACHE_CUSTOM_LOG="/proc/self/fd/1"
if [ "${ENABLE_WEB_ACCESS_LOG,,}" == "false" ]; then
export APACHE_CUSTOM_LOG="/dev/null"
fi
: ${EXPOSE_WEB_SERVER_INFO:="on"}
export APACHE_SERVER_TOKENS="OS"
export APACHE_SERVER_SIGNATURE="On"
if [ "${EXPOSE_WEB_SERVER_INFO}" == "off" ]; then
export APACHE_SERVER_TOKENS="Prod"
export APACHE_SERVER_SIGNATURE="Off"
fi
mkdir -p /tmp/httpd
}
prepare_zbx_web_config() {
echo "** Preparing Zabbix frontend configuration file"
PHP_CONFIG_FILE="/etc/php-fpm.d/zabbix.conf"
prepare_zbx_php_config() {
echo "** Preparing PHP configuration"
export PHP_FPM_PM=${PHP_FPM_PM:-"dynamic"}
export PHP_FPM_PM_MAX_CHILDREN=${PHP_FPM_PM_MAX_CHILDREN:-"50"}
@ -165,10 +194,10 @@ prepare_zbx_web_config() {
export PHP_FPM_PM_MAX_REQUESTS=${PHP_FPM_PM_MAX_REQUESTS:-"0"}
if [ "$(id -u)" == '0' ]; then
echo "user = zabbix" >> "$PHP_CONFIG_FILE"
echo "group = zabbix" >> "$PHP_CONFIG_FILE"
echo "listen.owner = nginx" >> "$PHP_CONFIG_FILE"
echo "listen.group = nginx" >> "$PHP_CONFIG_FILE"
echo "user = ${DAEMON_USER}" >> "$PHP_CONFIG_FILE"
echo "group = ${DAEMON_GROUP}" >> "$PHP_CONFIG_FILE"
echo "listen.owner = ${DAEMON_USER}" >> "$PHP_CONFIG_FILE"
echo "listen.group = ${DAEMON_GROUP}" >> "$PHP_CONFIG_FILE"
fi
: ${ZBX_DENY_GUI_ACCESS:="false"}
@ -222,45 +251,14 @@ prepare_zbx_web_config() {
: ${ZBX_ALLOW_HTTP_AUTH:="true"}
export ZBX_ALLOW_HTTP_AUTH=${ZBX_ALLOW_HTTP_AUTH}
}
prepare_zbx_config() {
if [ -n "${ZBX_SESSION_NAME}" ]; then
cp "$ZABBIX_WWW_ROOT/include/defines.inc.php" "/tmp/defines.inc.php_tmp"
sed "/ZBX_SESSION_NAME/s/'[^']*'/'${ZBX_SESSION_NAME}'/2" "/tmp/defines.inc.php_tmp" > "$ZABBIX_WWW_ROOT/include/defines.inc.php"
rm -f "/tmp/defines.inc.php_tmp"
fi
: ${HTTP_INDEX_FILE:="index.php"}
sed -i \
-e "s/{HTTP_INDEX_FILE}/${HTTP_INDEX_FILE}/g" \
"$ZABBIX_CONF_DIR/apache.conf"
if [ -f "$ZABBIX_CONF_DIR/apache_ssl.conf" ]; then
sed -i \
-e "s/{HTTP_INDEX_FILE}/${HTTP_INDEX_FILE}/g" \
"$ZABBIX_CONF_DIR/apache_ssl.conf"
fi
: ${ENABLE_WEB_ACCESS_LOG:="true"}
if [ "${ENABLE_WEB_ACCESS_LOG,,}" == "false" ]; then
sed -ri \
-e 's!^(\s*CustomLog)\s+\S+!\1 /dev/null!g' \
"$HTTPD_CONF_FILE"
fi
: ${EXPOSE_WEB_SERVER_INFO:="on"}
if [ "${EXPOSE_WEB_SERVER_INFO}" = "off" ]; then
sed -i \
-e "s/^\(\s*ServerTokens\).*\$/\1 Prod/g" \
"$HTTPD_CONF_FILE"
else
EXPOSE_WEB_SERVER_INFO="on"
fi
export EXPOSE_WEB_SERVER_INFO=${EXPOSE_WEB_SERVER_INFO}
sed -i \
-e "s/^\(\s*ServerSignature\).*\$/\1 ${EXPOSE_WEB_SERVER_INFO^}/g" \
"$HTTPD_CONF_FILE"
}
#################################################
@ -269,8 +267,9 @@ echo "** Deploying Zabbix web-interface (Apache) with MySQL database"
check_variables
check_db_connect
prepare_zbx_php_config
prepare_web_server
prepare_zbx_web_config
prepare_zbx_config
echo "########################################################"