From bc56a87c45f065ec433afdced37b450f79d0e7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:05:38 +0300 Subject: [PATCH 01/15] improve description --- wordpress/wp-cli.sh | 117 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 23 deletions(-) diff --git a/wordpress/wp-cli.sh b/wordpress/wp-cli.sh index d1f318c..a2bf98e 100755 --- a/wordpress/wp-cli.sh +++ b/wordpress/wp-cli.sh @@ -90,34 +90,105 @@ done # We need to sure '/var/www/html' exists for 'wp-cli' wait_for_service "wordpress" 9001 -# To enable NPP - Nginx Cache Preload action: -# ##################################################################### -# For Development Environment: -# - Cause HTTP_HOST is localhost, -# - Map the WordPress container's 'localhost' to Nginx's IP. -# - Note: This is a tricky hack and only used for the development environment! +# Resolve host +resolve_host() { + local host="$1" + local ipv4="" + local ip_fallback="" + local result=() + + # Try to get IPv4 address + if ping -4 -c 1 "${host}" &>/dev/null; then + ipv4=$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1) + fi + + # Fallback to find IP + if getent hosts "${host}" &>/dev/null; then + ip_fallback=$(getent hosts "${host}" | awk '{ print $1 }') + fi + + # No IP found + if [[ -z "${ipv4}" && -z "${ip_fallback}" ]]; then + return 1 + # If both IPv4 and fallback IP are found + elif [[ -n "${ipv4}" && -n "${ip_fallback}" ]]; then + if [[ "${ipv4}" == "${ip_fallback}" ]]; then + # If both IPs are equal, return only one + result+=("${ipv4}") + else + # If both IPs are different, return both + result+=("${ipv4}") + result+=("${ip_fallback}") + fi + # If only one IP is found + elif [[ -n "${ipv4}" ]]; then + result+=("${ipv4}") + else + result+=("${ip_fallback}") + fi + + printf "%s\n" "${result[@]}" +} + +# To enable NPP Plugin Nginx Cache Preload action: +# ############################################################################################################ +# The NPP WordPress plugin uses 'wget' with 'WP_SITEURL' from inside the WordPress container to Preload cache. +# This means that if 'WP_SITEURL' is set to "localhost", wget will attempt to fetch URLs from +# the container’s own loopback interface rather than reaching the Nginx server that handles +# cache preload requests. # -# For Production Environments: (Nginx sits on host or container) -# - I assume you use a publicly resolvable FQDN for WordPress (WP_SITEURL & WP_HOME); -# - Ensure outgoing traffic is allowed from the container. -# - Verify that /etc/resolv.conf in the container is correctly configured. -# - Verify that the container has internet access. -# + That's all for Cache Preload works like a charm. -####################################################################### +# To handle that; +# +# Development Environments: +# - During 'wp core install', the '--url' parameter is hardcoded as 'https://localhost', +# so WP_SITEURL ends up being 'https://localhost' within the container. +# - In this scenario, Nginx Cache Preload requests will try to access 'https://localhost', which +# incorrectly refers to the wordpress container itself. +# - To work around this, we update the wordpress container’s '/etc/hosts' file to remap 'localhost' to either +# 'host.docker.internal' or the actual 'Nginx container IP'. This forces to retrieve resources +# from the correct endpoint, enabling the Nginx Cache Preload action during development. +# - Keep in mind! Below settings will not work here because of priority issue in /etc/hosts +# extra_hosts: +# - "localhost:Nginx_LAN_IP" +# +# Production Environment: +# - WP_SITEURL is typically set to an FQDN (example.com) pointing to Nginx. +# - If the WordPress container has WAN access, can resolve external domains, and allows outgoing traffic, +# Cache Preload requests will correctly reach Nginx over the WAN route. +# - If the wordpress container lacks WAN access, external DNS resolution, or outgoing traffic: +# - WP_SITEURL (example.com) must resolve internally to Nginx LAN IP. (Nginx can sits on host or as a container) +# - Solutions: +# 1. Internal DNS resolver mapping WP_SITEURL to Nginx's LAN IP. +# 2. Manually adding WP_SITEURL to /etc/hosts inside the wordpress container. +# 3. Recommended docker way, edit wordpress service in docker-compose.yml, +# extra_hosts: +# - "example.com:Nginx_LAN_IP" +############################################################################################################### if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then - IP="${NPP_NGINX_IP}" - LINE="${IP} ${NPP_HTTP_HOST}" + # Create array + mapfile -t ip_array < <(resolve_host host.docker.internal) + + # Create temporary file + TEMP_HOSTS="$(mktemp /tmp/hosts.XXXXXX)" HOSTS="/etc/hosts" - # Check if the Nginx static IP defined - if ! grep -q "${IP}" "${HOSTS}"; then - # Map localhost to Nginx Static IP - echo -e "${LINE}\n$(cat ${HOSTS})" > /tmp/hosts.new - cat /tmp/hosts.new > "${HOSTS}" - rm -f /tmp/hosts.new - echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} Mapped '${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET}' to Nginx IP '${COLOR_LIGHT_CYAN}${IP}${COLOR_RESET}' in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." + # Hack /etc/hosts kindly, not make container upset + # Map to host.docker.internal if available + if (( ${#ip_array[@]} )); then + for IP in "${ip_array[@]}"; do + echo "${IP} ${NPP_HTTP_HOST}" >> "${TEMP_HOSTS}" + done + cat "${HOSTS}" >> "${TEMP_HOSTS}" + cat "${TEMP_HOSTS}" > "${HOSTS}" + echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to host.docker.internal ${COLOR_LIGHT_CYAN}${ip_array[@]}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." else - echo -e "${COLOR_YELLOW}${COLOR_BOLD}NPP-WP:${COLOR_RESET} Mapping already exists: '${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET}' -> '${COLOR_LIGHT_CYAN}${IP}${COLOR_RESET}'." + # Fallback, Map to NGINX container IP + IP="${NPP_NGINX_IP}" + LINE="${IP} ${NPP_HTTP_HOST}" + HOSTS="/etc/hosts" + echo -e "${LINE}\n$(cat ${HOSTS})" > "${TEMP_HOSTS}" + cat "${TEMP_HOSTS}" > "${HOSTS}" + echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to Nginx container IP ${COLOR_LIGHT_CYAN}${IP}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." fi fi ####################################################################### From 39aa36daf9cc920dc1704f7a578b861adcd4d57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:07:55 +0300 Subject: [PATCH 02/15] add host.docker.internal --- docker-compose.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 803f26e..1e70a7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,8 +63,10 @@ services: - /dev/fuse:/dev/fuse networks: npp_network: + extra_hosts: + - "host.docker.internal:host-gateway" post_start: - - command: /scripts/wp-cli.sh + - command: /scripts/wp-post.sh working_dir: ${NPP_WEB_ROOT_} user: root mem_limit: "2GB" From 5215ff1bb0b00d89600850a18e07d11b69c6351e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:08:13 +0300 Subject: [PATCH 03/15] Rename wp-cli.sh to wp-post.sh --- wordpress/{wp-cli.sh => wp-post.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename wordpress/{wp-cli.sh => wp-post.sh} (100%) diff --git a/wordpress/wp-cli.sh b/wordpress/wp-post.sh similarity index 100% rename from wordpress/wp-cli.sh rename to wordpress/wp-post.sh From a303d66e4cb1d2c3d0089c0891f610f39df8245e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:09:27 +0300 Subject: [PATCH 04/15] add iputils-ping --- wordpress/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wordpress/Dockerfile b/wordpress/Dockerfile index ae90fae..1fe9b20 100644 --- a/wordpress/Dockerfile +++ b/wordpress/Dockerfile @@ -43,6 +43,7 @@ RUN apt-get update && apt-get install -y \ # Install dependencies for service health checks mariadb-client \ netcat-traditional \ + iputils-ping \ # Install common dependencies curl \ # Install dev deploy dependencies @@ -104,11 +105,11 @@ RUN install-php-extensions ${PHP_EXTENSIONS} # Copy the scripts into the container COPY wordpress/entrypoint-wp.sh /entrypoint-wp.sh -COPY wordpress/wp-cli.sh /scripts/wp-cli.sh +COPY wordpress/wp-post.sh /scripts/wp-post.sh # Make sure scripts are executable RUN chmod +x /entrypoint-wp.sh -RUN chmod +x /scripts/wp-cli.sh +RUN chmod +x /scripts/wp-post.sh # Remove build time dependencies to keep image consistent RUN apt-get purge -y \ From 8dbd0502ed83707728244f81c70c73ea58dcd694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:24:10 +0300 Subject: [PATCH 05/15] Update wp-post.sh --- wordpress/wp-post.sh | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/wordpress/wp-post.sh b/wordpress/wp-post.sh index a2bf98e..7498c2a 100755 --- a/wordpress/wp-post.sh +++ b/wordpress/wp-post.sh @@ -98,14 +98,10 @@ resolve_host() { local result=() # Try to get IPv4 address - if ping -4 -c 1 "${host}" &>/dev/null; then - ipv4=$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1) - fi + ipv4=$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1) # Fallback to find IP - if getent hosts "${host}" &>/dev/null; then - ip_fallback=$(getent hosts "${host}" | awk '{ print $1 }') - fi + ip_fallback=$(getent hosts "${host}" | awk '{ print $1 }') # No IP found if [[ -z "${ipv4}" && -z "${ip_fallback}" ]]; then @@ -132,20 +128,20 @@ resolve_host() { # To enable NPP Plugin Nginx Cache Preload action: # ############################################################################################################ -# The NPP WordPress plugin uses 'wget' with 'WP_SITEURL' from inside the WordPress container to Preload cache. -# This means that if 'WP_SITEURL' is set to "localhost", wget will attempt to fetch URLs from -# the container’s own loopback interface rather than reaching the Nginx server that handles +# The NPP WordPress plugin uses "wget" with "WP_SITEURL" from inside the WordPress container to Preload cache. +# This means that if "WP_SITEURL" is set to "localhost", wget will attempt to fetch URLs from +# the containers own loopback interface rather than reaching the Nginx server that handles # cache preload requests. # # To handle that; # # Development Environments: -# - During 'wp core install', the '--url' parameter is hardcoded as 'https://localhost', -# so WP_SITEURL ends up being 'https://localhost' within the container. -# - In this scenario, Nginx Cache Preload requests will try to access 'https://localhost', which +# - During "wp core install", the "--url" parameter is hardcoded as "https://localhost", +# so WP_SITEURL ends up being "https://localhost" within the container. +# - In this scenario, Nginx Cache Preload requests will try to access "https://localhost", which # incorrectly refers to the wordpress container itself. -# - To work around this, we update the wordpress container’s '/etc/hosts' file to remap 'localhost' to either -# 'host.docker.internal' or the actual 'Nginx container IP'. This forces to retrieve resources +# - To work around this, we update the wordpress containers "/etc/hosts" file to remap "localhost" to either +# "host.docker.internal" or the actual "Nginx container IP". This forces to retrieve resources # from the correct endpoint, enabling the Nginx Cache Preload action during development. # - Keep in mind! Below settings will not work here because of priority issue in /etc/hosts # extra_hosts: @@ -164,6 +160,7 @@ resolve_host() { # extra_hosts: # - "example.com:Nginx_LAN_IP" ############################################################################################################### + if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then # Create array mapfile -t ip_array < <(resolve_host host.docker.internal) @@ -191,7 +188,7 @@ if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to Nginx container IP ${COLOR_LIGHT_CYAN}${IP}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." fi fi -####################################################################### +################################################################################################################ # Check ownership of webroot for consistency check_ownership() { From 3468957d62da79f8e9f843185f29671dab656a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:24:38 +0300 Subject: [PATCH 06/15] Update wp-post.sh --- wordpress/wp-post.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wordpress/wp-post.sh b/wordpress/wp-post.sh index 7498c2a..5da62d3 100755 --- a/wordpress/wp-post.sh +++ b/wordpress/wp-post.sh @@ -98,10 +98,10 @@ resolve_host() { local result=() # Try to get IPv4 address - ipv4=$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1) + ipv4="$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1)" # Fallback to find IP - ip_fallback=$(getent hosts "${host}" | awk '{ print $1 }') + ip_fallback="$(getent hosts "${host}" | awk '{ print $1 }')" # No IP found if [[ -z "${ipv4}" && -z "${ip_fallback}" ]]; then From 7ff49648a8f1072f69c6f6827810f1eac14a9915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:27:11 +0300 Subject: [PATCH 07/15] Update wp-post.sh --- wordpress/wp-post.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordpress/wp-post.sh b/wordpress/wp-post.sh index 5da62d3..18b417b 100755 --- a/wordpress/wp-post.sh +++ b/wordpress/wp-post.sh @@ -98,7 +98,7 @@ resolve_host() { local result=() # Try to get IPv4 address - ipv4="$(ping -4 -c 1 "$host" | awk -F'[()]' '{print $2}' | head -n 1)" + ipv4="$(ping -4 -c 1 "$host" | grep -oP '(?<=\()[^)]+' | head -n 1)" # Fallback to find IP ip_fallback="$(getent hosts "${host}" | awk '{ print $1 }')" From 882da949e0a1fa324caa0a00767066b2101cd803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:49:01 +0300 Subject: [PATCH 08/15] Update wp-post.sh --- wordpress/wp-post.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/wordpress/wp-post.sh b/wordpress/wp-post.sh index 18b417b..dd64001 100755 --- a/wordpress/wp-post.sh +++ b/wordpress/wp-post.sh @@ -64,7 +64,6 @@ for var in \ NPP_UID \ NPP_GID \ NPP_DEV_ENABLED \ - NPP_NGINX_IP \ NPP_HTTP_HOST \ NPP_DEV_PLUGIN_NAME \ NPP_DEV_PLUGIN_DIR \ @@ -160,7 +159,6 @@ resolve_host() { # extra_hosts: # - "example.com:Nginx_LAN_IP" ############################################################################################################### - if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then # Create array mapfile -t ip_array < <(resolve_host host.docker.internal) @@ -170,22 +168,15 @@ if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then HOSTS="/etc/hosts" # Hack /etc/hosts kindly, not make container upset - # Map to host.docker.internal if available + # Map to host.docker.internal if (( ${#ip_array[@]} )); then for IP in "${ip_array[@]}"; do echo "${IP} ${NPP_HTTP_HOST}" >> "${TEMP_HOSTS}" done + cat "${HOSTS}" >> "${TEMP_HOSTS}" cat "${TEMP_HOSTS}" > "${HOSTS}" echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to host.docker.internal ${COLOR_LIGHT_CYAN}${ip_array[@]}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." - else - # Fallback, Map to NGINX container IP - IP="${NPP_NGINX_IP}" - LINE="${IP} ${NPP_HTTP_HOST}" - HOSTS="/etc/hosts" - echo -e "${LINE}\n$(cat ${HOSTS})" > "${TEMP_HOSTS}" - cat "${TEMP_HOSTS}" > "${HOSTS}" - echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to Nginx container IP ${COLOR_LIGHT_CYAN}${IP}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." fi fi ################################################################################################################ From 30ec73adf0cc801763c229c0e34ff31dff34311c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:51:43 +0300 Subject: [PATCH 09/15] disable static IP --- docker-compose.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1e70a7f..5093783 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,6 @@ services: if (defined('WP_CLI') && WP_CLI && !isset($$_SERVER['HTTP_HOST'])) $$_SERVER['HTTP_HOST'] = "${NPP_HTTP_HOST}"; - NPP_WEB_ROOT=${NPP_WEB_ROOT_} - NPP_NGINX_CACHE_PATH=${NPP_NGINX_CACHE_PATH_} - - NPP_NGINX_IP=${NPP_NGINX_IP} - NPP_HTTP_HOST=${NPP_HTTP_HOST} - NPP_USER=${NPP_USER_} - NPP_UID=${NPP_UID_} @@ -152,7 +151,6 @@ services: - MOUNT_DIR=${MOUNT_DIR_} networks: npp_network: - ipv4_address: 172.19.84.1 mem_limit: "1.5GB" mem_reservation: "1GB" cpus: "1.0" @@ -180,7 +178,3 @@ networks: name: npp-wp driver: bridge enable_ipv6: false - ipam: - config: - - subnet: "172.19.0.0/16" - gateway: "172.19.0.1" From c51a20faa83c576c45a3d04609eb2d6d6ca08edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 18:52:23 +0300 Subject: [PATCH 10/15] drop nginx IP --- .env | 1 - 1 file changed, 1 deletion(-) diff --git a/.env b/.env index 8281e95..3a55bdd 100644 --- a/.env +++ b/.env @@ -25,7 +25,6 @@ export NGINX_CACHE=nginx_cache export NGINX_CONF=./nginx/nginx.conf export NPP_NGINX_CONF=./nginx/default.conf export NPP_NGINX_PARAMS_CONF=./nginx/fastcgi_params -export NPP_NGINX_IP=172.19.84.1 export NPP_HTTP_HOST=localhost # WP-CLI Settings From baa6d71baefed506d11a8283d84208f22c76f6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 19:01:35 +0300 Subject: [PATCH 11/15] Update entrypoint-wp.sh --- wordpress/entrypoint-wp.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/wordpress/entrypoint-wp.sh b/wordpress/entrypoint-wp.sh index 90781e8..e381d03 100755 --- a/wordpress/entrypoint-wp.sh +++ b/wordpress/entrypoint-wp.sh @@ -44,7 +44,6 @@ for var in \ NPP_GID \ NPP_NGINX_CACHE_PATH \ NPP_USER \ - NPP_DEV_ENABLED \ MOUNT_DIR; do if [[ -z "${!var:-}" ]]; then echo -e "${COLOR_RED}${COLOR_BOLD}NPP-WP-FATAL:${COLOR_RESET} Missing required environment variable(s): ${COLOR_LIGHT_CYAN}${var}${COLOR_RESET} - ${COLOR_RED}Exiting...${COLOR_RESET}" From fe106b6e23fbd06d1b63b31ee9709c4c6ddbef95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 19:10:30 +0300 Subject: [PATCH 12/15] Update .env --- .env | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 3a55bdd..ada66ac 100644 --- a/.env +++ b/.env @@ -55,14 +55,15 @@ export NPP_GID_=33749 # NPP Development environment export NPP_DEV_ENABLED_=1 +export NPP_HACK_HOST_=1 export NPP_DEV_PLUGIN_NAME_=fastcgi-cache-purge-and-preload-nginx export NPP_DEV_PLUGIN_DIR_="${NPP_WEB_ROOT_}/wp-content/plugins/${NPP_DEV_PLUGIN_NAME_}" export NPP_DEV_TMP_CLONE_DIR_="/tmp/${NPP_DEV_PLUGIN_NAME_}" export NPP_DEV_PLUGIN_FILE_="${NPP_DEV_PLUGIN_DIR_}/${NPP_DEV_PLUGIN_NAME_}.php" export NPP_DEV_GITHUB_REPO_="https://github.com/psaux-it/nginx-fastcgi-cache-purge-and-preload.git" -# Plugins to auto Install (comma seperated) - Dev Tools -export NPP_PLUGINS_="${NPP_DEV_PLUGIN_NAME_},query-monitor,plugin-check,wp-crontrol,health-check" +# Plugins to auto Install (comma seperated) +export NPP_PLUGINS_="${NPP_DEV_PLUGIN_NAME_}" # Themes to auto Install (comma seperated) export NPP_THEMES_="blue-note" From 15b908490e062f6f974742baa08ddce568fcb1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 19:12:38 +0300 Subject: [PATCH 13/15] Update docker-compose.yml --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 5093783..16d2786 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,6 +39,7 @@ services: - NPP_GID=${NPP_GID_} - NPP_PLUGINS=${NPP_PLUGINS_} - NPP_THEMES=${NPP_THEMES_} + - NPP_HACK_HOST=${NPP_HACK_HOST_} - NPP_DEV_ENABLED=${NPP_DEV_ENABLED_} - NPP_DEV_PLUGIN_NAME=${NPP_DEV_PLUGIN_NAME_} - NPP_DEV_PLUGIN_DIR=${NPP_DEV_PLUGIN_DIR_} From c5f54d77ed1814d5fee35863c90d3494ac000eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 19:17:35 +0300 Subject: [PATCH 14/15] Update wp-post.sh --- wordpress/wp-post.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wordpress/wp-post.sh b/wordpress/wp-post.sh index dd64001..35c8c2d 100755 --- a/wordpress/wp-post.sh +++ b/wordpress/wp-post.sh @@ -65,6 +65,7 @@ for var in \ NPP_GID \ NPP_DEV_ENABLED \ NPP_HTTP_HOST \ + NPP_HACK_HOST \ NPP_DEV_PLUGIN_NAME \ NPP_DEV_PLUGIN_DIR \ NPP_DEV_TMP_CLONE_DIR \ @@ -126,11 +127,11 @@ resolve_host() { } # To enable NPP Plugin Nginx Cache Preload action: -# ############################################################################################################ -# The NPP WordPress plugin uses "wget" with "WP_SITEURL" from inside the WordPress container to Preload cache. +# ################################################################################################################## +# The NPP WordPress plugin uses "wget" with "WP_SITEURL" from inside the WordPress container to Preload Nginx Cache. # This means that if "WP_SITEURL" is set to "localhost", wget will attempt to fetch URLs from # the containers own loopback interface rather than reaching the Nginx server that handles -# cache preload requests. +# Cache Preload requests. # # To handle that; # @@ -158,8 +159,8 @@ resolve_host() { # 3. Recommended docker way, edit wordpress service in docker-compose.yml, # extra_hosts: # - "example.com:Nginx_LAN_IP" -############################################################################################################### -if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then +################################################################################################################### +if [[ "${NPP_HACK_HOST}" -eq 1 ]]; then # Create array mapfile -t ip_array < <(resolve_host host.docker.internal) @@ -179,7 +180,7 @@ if [[ "${NPP_DEV_ENABLED}" -eq 1 ]]; then echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-WP:${COLOR_RESET} ${COLOR_RED}Hacked!${COLOR_RESET} Mapped ${COLOR_LIGHT_CYAN}${NPP_HTTP_HOST}${COLOR_RESET} to host.docker.internal ${COLOR_LIGHT_CYAN}${ip_array[@]}${COLOR_RESET} in ${COLOR_LIGHT_CYAN}${HOSTS}${COLOR_RESET}." fi fi -################################################################################################################ +#################################################################################################################### # Check ownership of webroot for consistency check_ownership() { From b0df612e2538d78f430c1155c35919acccd15100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20=C3=87ALI=C5=9EIR?= Date: Fri, 14 Feb 2025 22:38:24 +0300 Subject: [PATCH 15/15] nginx :ro --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 16d2786..9ce3eed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -134,7 +134,7 @@ services: depends_on: - wordpress volumes: - - ${WORDPRESS_HOME}:${NPP_WEB_ROOT_} + - ${WORDPRESS_HOME}:${NPP_WEB_ROOT_}:ro - ${NGINX_CACHE}:${NPP_NGINX_CACHE_PATH_} - ${NGINX_CONF}:/etc/nginx/nginx.conf - ${NPP_NGINX_CONF}:/etc/nginx/conf.d/default.conf