Skip to content

Commit a82d7df

Browse files
authored
PR #5 from psaux-it/fallback
fallback_localhost
2 parents e5a3e1f + 051d151 commit a82d7df

File tree

11 files changed

+305
-245
lines changed

11 files changed

+305
-245
lines changed

.env

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# NPP environment file
1+
# Environment for NPP-Optimized WordPress Setup #
2+
# ---------------------------------------------------------------------------- #
3+
# Author: [Hasan ÇALIŞIR] #
4+
# Purpose: Full-stack Dockerized environment for NPP WordPress plugin, including #
5+
# WordPress, PHP-FPM, Nginx, MySQL, WP-CLI, and necessary PHP extensions. #
6+
# ---------------------------------------------------------------------------- #
27

38
# Wordpress Settings
49
export WORDPRESS_HOME=wordpress
@@ -18,13 +23,13 @@ export NPP_MYSQL_CONF=./mysql/50-npp-server.cnf
1823
# Nginx Settings
1924
export NGINX_CACHE=nginx_cache
2025
export NGINX_CONF=./nginx/nginx.conf
21-
export NPP_NGINX_CONF=./nginx/npp.conf
26+
export NPP_NGINX_CONF=./nginx/default.conf
2227
export NPP_NGINX_PARAMS_CONF=./nginx/fastcgi_params
23-
export NGINX_LOGS=./logs/nginx
24-
export NPP_NGINX_IP=172.19.0.3
28+
export NPP_NGINX_IP=172.19.84.1
29+
export NPP_HTTP_HOST=localhost
2530

2631
# WP-CLI Settings
27-
export WORDPRESS_SITE_URL_="https://${NPP_NGINX_IP}"
32+
export WORDPRESS_SITE_URL_="https://${NPP_HTTP_HOST}"
2833
export WORDPRESS_SITE_TITLE_="NPP Dockerized"
2934
export WORDPRESS_ADMIN_USER_=npp
3035
export WORDPRESS_ADMIN_PASSWORD_=npp
@@ -49,16 +54,16 @@ export NPP_USER_=npp
4954
export NPP_UID_=18978
5055
export NPP_GID_=33749
5156

52-
# NPP Switch Development environment
57+
# NPP Development environment
5358
export NPP_DEV_ENABLED_=1
5459
export NPP_DEV_PLUGIN_NAME_=fastcgi-cache-purge-and-preload-nginx
5560
export NPP_DEV_PLUGIN_DIR_="${NPP_WEB_ROOT_}/wp-content/plugins/${NPP_DEV_PLUGIN_NAME_}"
5661
export NPP_DEV_TMP_CLONE_DIR_="/tmp/${NPP_DEV_PLUGIN_NAME_}"
5762
export NPP_DEV_PLUGIN_FILE_="${NPP_DEV_PLUGIN_DIR_}/${NPP_DEV_PLUGIN_NAME_}.php"
5863
export NPP_DEV_GITHUB_REPO_="https://github.com/psaux-it/nginx-fastcgi-cache-purge-and-preload.git"
5964

60-
# Plugins to Install (comma seperated)
61-
export NPP_PLUGINS_="fastcgi-cache-purge-and-preload-nginx"
65+
# Plugins to auto Install (comma seperated)
66+
export NPP_PLUGINS_="${NPP_DEV_PLUGIN_NAME_}, contact-form-7"
6267

63-
# Default Theme
68+
# Themes to auto Install (comma seperated)
6469
export NPP_THEMES_="blue-note"

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ Explore the **[NPP Main GitHub Repository](https://github.com/psaux-it/nginx-fas
1616
- ✅ Supports a wide range of **PHP extensions**
1717
- ✅ Easily switch between the **stable** release and the **bleeding-edge dev** version of the **NPP**
1818
- ✅ All containers powered by **Debian 12** for a stable, consistent environment
19+
- ✅ Compatible with Windows WSL and Linux Hosts
1920

2021
## 🔑 Environment Variables
2122

2223
Please check the **.env** file for the environment variables used by the project.
2324

2425
Some variables can be directly modified by the user to customize the setup easily, while others are hard depend to the project's core configuration. Modifying these core variables for a production environment may require adjustments in other parts of the project to ensure proper integration and workflow. Feel free to customize it to meet your full-stack WordPress **production** needs!
2526

26-
#### Use the Bleeding-Edge Version of NPP or Contribute to Development
27+
#### Use the Bleeding-Edge Version of NPP or Contribute to Development (Default)
2728

2829
If you want to use the **latest bleeding-edge version** of the NPP plugin or set up a **development/test environment**, simply set the following environment variable:
2930

@@ -62,8 +63,8 @@ docker compose up -d --build
6263

6364
### 🚀 **Post-Container Startup Access**
6465
- The WordPress site can be accessed at the host machine:
65-
- 🔒 [https://172.19.0.3](https://172.19.0.3)
66-
- 🌐 [http://172.19.0.3](http://172.19.0.3)
66+
- 🔒 [https://localhost](https://localhost)
67+
- 🌐 [http://localhost](http://localhost)
6768

6869
- Default WordPress **wp-admin** login credentials:
6970
- **Username**: `npp`

docker-compose.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ services:
1616
- ${WORDPRESS_HOME}:${NPP_WEB_ROOT_}
1717
- ${NGINX_CACHE}:${NPP_NGINX_CACHE_PATH_}
1818
- ${NGINX_CONF}:/etc/nginx/nginx.conf
19-
- ${NPP_NGINX_CONF}:/etc/nginx/conf.d/npp.conf
19+
- ${NPP_NGINX_CONF}:/etc/nginx/conf.d/default.conf
2020
- ${NPP_FPM_CONF}:/usr/local/etc/php-fpm.d/www.conf
2121
- ${FPM_DOCKER_CONF}:/usr/local/etc/php-fpm.d/zz-docker.conf
2222
- ${NPP_PHP_CONF}:/usr/local/etc/php/conf.d/npp.ini
@@ -30,9 +30,11 @@ services:
3030
- WORDPRESS_CONFIG_EXTRA=
3131
define('FORCE_SSL_ADMIN', true);
3232
define('FORCE_SSL_LOGIN', true);
33-
if (defined('WP_CLI') && WP_CLI && !isset($$_SERVER['HTTP_HOST'])) $$_SERVER['HTTP_HOST'] = "${NPP_NGINX_IP}";
33+
if (defined('WP_CLI') && WP_CLI && !isset($$_SERVER['HTTP_HOST'])) $$_SERVER['HTTP_HOST'] = "${NPP_HTTP_HOST}";
3434
- NPP_WEB_ROOT=${NPP_WEB_ROOT_}
3535
- NPP_NGINX_CACHE_PATH=${NPP_NGINX_CACHE_PATH_}
36+
- NPP_NGINX_IP=${NPP_NGINX_IP}
37+
- NPP_HTTP_HOST=${NPP_HTTP_HOST}
3638
- NPP_USER=${NPP_USER_}
3739
- NPP_UID=${NPP_UID_}
3840
- NPP_GID=${NPP_GID_}
@@ -61,7 +63,6 @@ services:
6163
- /dev/fuse:/dev/fuse
6264
networks:
6365
npp_network:
64-
ipv4_address: 172.19.0.4
6566
post_start:
6667
- command: /scripts/wp-cli.sh
6768
working_dir: ${NPP_WEB_ROOT_}
@@ -104,7 +105,6 @@ services:
104105
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
105106
networks:
106107
npp_network:
107-
ipv4_address: 172.19.0.2
108108
mem_limit: "2GB"
109109
mem_reservation: "1GB"
110110
cpus: "1.0"
@@ -135,7 +135,7 @@ services:
135135
- ${WORDPRESS_HOME}:${NPP_WEB_ROOT_}
136136
- ${NGINX_CACHE}:${NPP_NGINX_CACHE_PATH_}
137137
- ${NGINX_CONF}:/etc/nginx/nginx.conf
138-
- ${NPP_NGINX_CONF}:/etc/nginx/conf.d/npp.conf
138+
- ${NPP_NGINX_CONF}:/etc/nginx/conf.d/default.conf
139139
- ${NPP_NGINX_PARAMS_CONF}:/etc/nginx/fastcgi_params
140140
- ${NGINX_SSL_CERTS}:/etc/ssl:ro
141141
- /etc/localtime:/etc/localtime:ro
@@ -146,11 +146,11 @@ services:
146146
- NPP_UID=${NPP_UID_}
147147
- NPP_GID=${NPP_GID_}
148148
- NGINX_WEB_USER=${NGINX_WEB_USER_}
149-
- NPP_NGINX_IP=${NPP_NGINX_IP}
149+
- NPP_HTTP_HOST=${NPP_HTTP_HOST}
150150
- MOUNT_DIR=${MOUNT_DIR_}
151151
networks:
152152
npp_network:
153-
ipv4_address: 172.19.0.3
153+
ipv4_address: 172.19.84.1
154154
mem_limit: "1.5GB"
155155
mem_reservation: "1GB"
156156
cpus: "1.0"
@@ -167,11 +167,17 @@ volumes:
167167
wordpress-db:
168168
wordpress:
169169
nginx_cache:
170+
driver: local
171+
driver_opts:
172+
type: tmpfs
173+
device: tmpfs
174+
o: size=500m
170175

171176
networks:
172177
npp_network:
173178
name: npp-wp
174179
driver: bridge
180+
enable_ipv6: false
175181
ipam:
176182
config:
177183
- subnet: "172.19.0.0/16"

fpm/www.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
user = npp
44
group = npp
5-
listen = 127.0.0.1:9001
5+
listen = 0.0.0.0:9001
66
pm = dynamic
77
pm.max_children = 8
88
pm.start_servers = 4

fpm/zz-docker.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
[global]
22
daemonize = no
3-
4-
[www]
5-
listen = 9001

nginx/default.conf

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Nginx VHOST for NPP-Optimized WordPress Setup #
2+
# ---------------------------------------------------------------------------- #
3+
# Author: [Hasan ÇALIŞIR] #
4+
# Purpose: Full-stack Dockerized environment for NPP WordPress plugin, including #
5+
# WordPress, PHP-FPM, Nginx, MySQL, WP-CLI, and necessary PHP extensions. #
6+
# ---------------------------------------------------------------------------- #
7+
8+
# FastCGI Cache Path
9+
####################
10+
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=NPP:100m max_size=400m inactive=30d;
11+
####################
12+
13+
server {
14+
# Listen HTTP
15+
##################################
16+
listen 80;
17+
server_name localhost;
18+
19+
# HTTPS Redirect
20+
##################################
21+
location / {
22+
rewrite ^ https://$host$request_uri? permanent;
23+
}
24+
}
25+
26+
server {
27+
# Listen HTTPS
28+
##################################
29+
listen 443 ssl;
30+
server_name localhost;
31+
32+
# Document root
33+
###############
34+
root /var/www/html;
35+
index index.php index.html index.htm;
36+
37+
# Cache Settings
38+
#################
39+
set $skip_cache 0;
40+
41+
if ($query_string != "") {
42+
set $skip_cache 1;
43+
}
44+
45+
if ($request_uri ~* "(?:/add-to-cart=.*|/cart/.*|/my-account/.*|/checkout/.*|/wp-json/.*|/wc-api/.*|/addons.*|/wp-admin(?:/.*)?|/robots\.txt|/xmlrpc\.php|wp-.*\.php|/feed/.*|index\.php|sitemap(_index)?\.xml|[a-z0-9_-]+-sitemap([0-9]+)?\.(xml|html)|/sitemap\.html)") {
46+
set $skip_cache 1;
47+
}
48+
49+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
50+
set $skip_cache 1;
51+
}
52+
53+
if ($http_cookie ~* "woocommerce_items_in_cart") {
54+
set $skip_cache 1;
55+
}
56+
57+
if ($arg_add-to-cart != "") {
58+
set $skip_cache 1;
59+
}
60+
# End
61+
#####
62+
63+
# Stop Nginx from logging
64+
#########################
65+
location = /favicon.ico {
66+
log_not_found off;
67+
access_log off;
68+
}
69+
70+
location = /robots.txt {
71+
log_not_found off;
72+
access_log off;
73+
allow all;
74+
}
75+
# End
76+
#####
77+
78+
# Serve content
79+
##################
80+
location / {
81+
try_files $uri $uri/ /index.php$is_args$args;
82+
}
83+
# End
84+
#####
85+
86+
# PHP-FPM Configuration
87+
################
88+
location ~ \.php$ {
89+
# Use NPP "Cache Key Regex" option for non-default structers
90+
# This structer supported in default by NPP
91+
############################################################
92+
fastcgi_cache_key "$scheme$request_method$host$request_uri";
93+
############################################################
94+
95+
try_files $uri =404;
96+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
97+
fastcgi_index index.php;
98+
fastcgi_pass wordpress-fpm:9001;
99+
include /etc/nginx/fastcgi_params;
100+
fastcgi_cache_bypass $skip_cache;
101+
fastcgi_no_cache $skip_cache;
102+
fastcgi_cache NPP;
103+
fastcgi_cache_valid 30d;
104+
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
105+
fastcgi_cache_lock on;
106+
}
107+
# End
108+
#####
109+
110+
# WP Security Settings
111+
#######################
112+
# Deny access to hidden files and directories (except .well-known)
113+
location ~ /\.(?!well-known/) {
114+
deny all;
115+
}
116+
117+
# Deny access to wp-config files and other critical files
118+
location ~* ^/(?:wp-config\.php|wp-config-sample\.php|readme\.html|license\.txt)$ {
119+
deny all;
120+
}
121+
122+
# Deny access to PHP files in uploads, files, plugins, themes
123+
location ~* /(?:uploads|files|wp-content|wp-includes)/.*\.php$ {
124+
deny all;
125+
}
126+
127+
# Deny access to script file types
128+
location ~* .(pl|cgi|py|sh|lua|asp)$ {
129+
deny all;
130+
}
131+
132+
# Block access to wp-content plugin/theme log files
133+
location ~* ^/wp-content/(plugins|themes)/.*\.(txt|log|md)$ {
134+
deny all;
135+
}
136+
137+
# Block common attack patterns
138+
location ~* "(eval\(.*\)|base64_encode\(.*\)|\{0\}|phpinfo|self/environ)" {
139+
deny all;
140+
}
141+
142+
# Block dangerous file access
143+
location ~* "/(thumb|timthumb|config|settings|sqlpatch|webshell|phpinfo)\.php" {
144+
deny all;
145+
}
146+
# End
147+
#####
148+
149+
# Browser Cache (Enable on Production)
150+
###############
151+
# location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
152+
# expires max;
153+
# log_not_found off;
154+
# access_log off;
155+
# }
156+
# End
157+
#####
158+
159+
# Dummy Self-Signed SSL Certificate (Don't use on Production)
160+
#################
161+
ssl_certificate /etc/ssl/fullchain.pem;
162+
ssl_certificate_key /etc/ssl/privkey.pem;
163+
ssl_trusted_certificate /etc/ssl/chain.pem;
164+
# End
165+
#####
166+
167+
# SSL Settings (Enable on Production)
168+
##############
169+
# ssl_protocols TLSv1.2 TLSv1.3;
170+
# ssl_prefer_server_ciphers on;
171+
# ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
172+
# ssl_ecdh_curve secp384r1;
173+
# ssl_session_cache shared:SSLA:10m;
174+
# ssl_session_timeout 10m;
175+
# ssl_session_tickets off;
176+
# ssl_buffer_size 4k;
177+
# End
178+
#####
179+
180+
# Security Headers (Enable on Production)
181+
##################
182+
# add_header Content-Security-Policy upgrade-insecure-requests;
183+
# add_header Permissions-Policy "microphone=(), camera=(), interest-cohort=(), browsing-topics=()";
184+
# add_header Referrer-Policy no-referrer-when-downgrade;
185+
# add_header X-Frame-Options "SAMEORIGIN";
186+
# add_header X-Content-Type-Options "nosniff";
187+
# add_header X-XSS-Protection "1; mode=block";
188+
# add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
189+
# End
190+
#####
191+
192+
# FastCGI Cache Status Header
193+
#############################
194+
add_header NPP-FastCGI-Cache $upstream_cache_status;
195+
#############################
196+
}

nginx/entrypoint-nginx.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ wait_for_service "wordpress" 9001
6565
wait_for_service "wordpress" 9999
6666

6767
# Check if required environment variables are set
68-
for var in NPP_UID NPP_GID NPP_USER NPP_WEB_ROOT NGINX_WEB_USER MOUNT_DIR NPP_NGINX_IP; do
68+
for var in \
69+
NPP_UID \
70+
NPP_GID \
71+
NPP_USER \
72+
NPP_WEB_ROOT \
73+
NGINX_WEB_USER \
74+
MOUNT_DIR \
75+
NPP_HTTP_HOST; do
6976
if [[ -z "${!var:-}" ]]; then
7077
echo -e "${COLOR_RED}${COLOR_BOLD}NPP-NGINX-FATAL:${COLOR_RESET} Missing required environment variable: ${COLOR_LIGHT_CYAN}${var}${COLOR_RESET} - ${COLOR_RED}Exiting...${COLOR_RESET}"
7178
exit 1
@@ -106,7 +113,7 @@ echo -e "\n${COLOR_YELLOW}━━━━━━━━━━━━━━━━━━
106113

107114
# URL Access Information
108115
echo -e "\n${COLOR_GREEN}${COLOR_BOLD}🔑 Access WordPress:${COLOR_RESET}"
109-
echo -e "${COLOR_LIGHT_CYAN}URL: ${COLOR_RESET}${COLOR_BOLD}https://${NPP_NGINX_IP}/wp-admin${COLOR_RESET}"
116+
echo -e "${COLOR_LIGHT_CYAN}URL: ${COLOR_RESET}${COLOR_BOLD}https://${NPP_HTTP_HOST}/wp-admin${COLOR_RESET}"
110117

111118
# Separator for credentials
112119
echo -e "\n${COLOR_YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${COLOR_RESET}"

0 commit comments

Comments
 (0)