Nginx Configuration β PHP Site Without WordPress
π Basic Nginx Config for Custom PHP Site
This config assumes you're running a plain PHP site (no WordPress). It serves clean folder structures like /contact/index.php
and uses a custom 404.html
page.
server {
listen 8080;
listen [::]:8080;
server_name foxiandmolly.dk www1.foxiandmolly.dk;
root /var/www/foxiandmolly.dk;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS "on";
fastcgi_param SERVER_PORT 443;
fastcgi_pass 127.0.0.1:{{php_fpm_port}};
fastcgi_param PHP_VALUE "{{php_settings}}";
}
error_page 404 /404.html;
location = /404.html {
alias /var/www/foxiandmolly.dk/404.html;
internal;
}
}
π Recommended Folder Structure
Files are organized into folders, with each folder containing its own index.php
or similar logic.
/var/www/foxiandmolly.dk/
βββ index.php
βββ 404.html
βββ contact/
β βββ index.php
βββ about/
β βββ info.php
π§ How It Works
This config is designed for custom or static PHP sites. It does not include WordPress rewrite rules. It's simple and fast:
- βοΈ URLs like
/contact/
go to /contact/index.php
- βοΈ No WordPress or routing logic required
- βοΈ PHP files are handled normally
- βοΈ If a file doesn't exist,
404.html
is shown
π οΈ Optional: Clean URL Router
If you're using a custom PHP router and want clean URLs like /page/about
, replace the main location block with:
location / {
try_files $uri $uri/ /index.php?$args;
}
π‘ Tip: Reload and Test
After editing your Nginx config, always test and reload:
sudo nginx -t
sudo systemctl reload nginx
Nginx Config β Multiple Standalone WordPress Sites in Subdirectories
π Nginx Config for WP in Folders like /olga/, /petra/
This config allows separate WordPress installs in subfolders like /olga/
and /petra/
, each with its own wp-config.php
. Useful when avoiding WordPress Multisite.
server {
listen 8080;
listen [::]:8080;
server_name foxiandmolly.dk www1.foxiandmolly.dk;
root /var/www/foxiandmolly.dk;
index index.php index.html;
location = / {
return 302 /olga/; # Optional: redirect to default subsite
}
# OLGA site
location /olga/ {
root /var/www/foxiandmolly.dk;
index index.php index.html;
try_files $uri $uri/ /olga/index.php?$args;
}
location ~ ^/olga/.*\.php$ {
root /var/www/foxiandmolly.dk;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS "on";
fastcgi_param SERVER_PORT 443;
fastcgi_pass 127.0.0.1:{{php_fpm_port}};
fastcgi_param PHP_VALUE "{{php_settings}}";
}
# PETRA site
location /petra/ {
root /var/www/foxiandmolly.dk;
index index.php index.html;
try_files $uri $uri/ /petra/index.php?$args;
}
location ~ ^/petra/.*\.php$ {
root /var/www/foxiandmolly.dk;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS "on";
fastcgi_param SERVER_PORT 443;
fastcgi_pass 127.0.0.1:{{php_fpm_port}};
fastcgi_param PHP_VALUE "{{php_settings}}";
}
error_page 404 /404.html;
location = /404.html {
alias /var/www/foxiandmolly.dk/404.html;
internal;
}
}
π Folder Structure for Multi-Site Setup
Each subfolder contains a full, standalone WordPress installation. The root folder acts like a container or optional redirect.
/var/www/foxiandmolly.dk/
βββ index.php β optional, can redirect to /olga/
βββ 404.html
βββ olga/
β βββ wp-config.php
β βββ wp-content/
β βββ index.php
βββ petra/
βββ wp-config.php
βββ wp-content/
βββ index.php
π§ How It Works
This config treats each folder like a separate WordPress site:
- βοΈ
/olga/
is a full WP site
- βοΈ
/petra/
is another WP site
- βοΈ Each has its own admin panel, themes, plugins, etc.
- π« Not using WordPress Multisite β no shared database
π‘ Tips for Clean Operation
- πΎ Always point the browser to
/olga/
or /petra/
directly
- π Optional: Add a landing page or auto-redirect in root
- π Use the same PHP block logic for any new subfolder
CloudPanel β options for cache settings
β‘ Varnish Cache (CloudPanel)
- π Purpose: Full-page HTTP caching layer for fast page delivery.
- π What it caches: Entire HTML pages (output from PHP).
- βοΈ How it helps: Reduces server load by skipping PHP/database on repeat requests.
- π§Ή "Purge entire cache": Clears all cached pages. Use after big content or layout changes.
- β Watch out: Might show outdated content if not excluded from dynamic pages like logins or carts.
- β
Best for: Static or semi-static pages β homepage, articles, product listings, etc.
π§ PageSpeed (mod_pagespeed) (CloudPanel)
- π¦ Purpose: Automatically optimizes frontend assets (CSS, JS, images, HTML).
- π What it does: Minifies, inlines, defers scripts, converts images to WebP, and more.
- π How it helps: Reduces page size and speeds up load times without manual changes.
- π§Ή "Purge Cache": Clears stored optimized assets. Use when CSS/JS updates donβt show up.
- β Watch out: Can break layout or scripts if filters are too aggressive.
- β
Best for: Automatic frontend optimization with minimal effort.