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:
πŸ› οΈ 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:
πŸ’‘ Tips for Clean Operation

CloudPanel – options for cache settings

⚑ Varnish Cache (CloudPanel)
🧠 PageSpeed (mod_pagespeed) (CloudPanel)