keepcalculator

06 Numbers and Powers

WordPress Multisite with Nginx Setup Guide

Card No. 06·70020 · Updated · Standard formula, shown below

This guide walks you through setting up WordPress Multisite on an Nginx web server. You’ll learn how to configure WordPress for subdomain or subdirectory networks, adjust Nginx server blocks, and handle rewrites so all sites in your network work correctly. By the end, you’ll have a working multisite installation with clean URLs and proper static file handling.

What You’ll Need

  • A server running Linux (Ubuntu/Debian recommended) with Nginx installed.
  • PHP-FPM installed and configured to work with Nginx.
  • MySQL or MariaDB database server.
  • WordPress files downloaded and extracted to your web root.
  • Domain name (or subdomain) pointed to your server’s IP.
  • SSL certificate (optional but recommended) – you can use Let’s Encrypt.
  • SSH access to your server with sudo privileges.

Step-by-Step

  1. Create a database for WordPress
    Log into MySQL: mysql -u root -p. Run:
    CREATE DATABASE wp_multisite;
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strong_password';
    GRANT ALL PRIVILEGES ON wp_multisite.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    Exit MySQL.
  2. Configure wp-config.php
    In your WordPress root, copy wp-config-sample.php to wp-config.php and edit it. Add your database credentials. Then add the following lines before /* That's all, stop editing! */:
    define('WP_ALLOW_MULTISITE', true);
    Save the file.
  3. Install WordPress normally
    Visit your domain in a browser and complete the standard WordPress installation (choose a language, set admin user, etc.).
  4. Enable Multisite in the dashboard
    Go to Tools → Network Setup. Choose either Subdomains (e.g., site1.example.com) or Subdirectories (e.g., example.com/site1). Subdomains require wildcard DNS and SSL for each subdomain. Click Install.
  5. Update wp-config.php with network settings
    WordPress will display code to add to wp-config.php. It looks like:
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true); (or false for subdirectories)
    define('DOMAIN_CURRENT_SITE', 'example.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
    Add these lines to your wp-config.php.
  6. Add rewrite rules to .htaccess (if using Apache)
    If you’re using Nginx, ignore this step. For Nginx, we’ll handle rewrites in the server block.
  7. Configure Nginx server block
    Edit your Nginx site configuration (e.g., /etc/nginx/sites-available/example.com). Here’s a basic server block for a subdomain multisite:
    server {
        listen 80;
        server_name example.com *.example.com;
        root /var/www/example.com;
        index index.php;
    
        # Logs
        access_log /var/log/nginx/example.com.access.log;
        error_log /var/log/nginx/example.com.error.log;
    
        # WordPress multisite subdomain rewrite rules
        if (!-e $request_filename) {
            rewrite ^/wp-admin$ /wp-admin/ permanent;
            rewrite ^(/[^/]+)?(/wp-.*) $2 last;
            rewrite ^(/[^/]+)?(/.*\.php) $2 last;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        }
    
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
            expires max;
            log_not_found off;
        }
    }
    

    For subdirectory multisite, use server_name example.com; and the same rewrite rules work.

  8. Test Nginx configuration and reload
    Run sudo nginx -t to check for syntax errors. Then sudo systemctl reload nginx.
  9. Add wildcard DNS (for subdomains)
    If you chose subdomains, create a wildcard A record: *.example.com pointing to your server IP. For subdirectories, no extra DNS needed.
  10. Log in and create new sites
    Go to My Sites → Network Admin → Sites and add new sites. For subdomains, the site URL will be like site1.example.com; for subdirectories, example.com/site1.
  11. Update permalinks
    Go to Network Admin → Settings and set permalink structure (e.g., Post name). Then visit each site’s permalink settings to flush rewrite rules.

Common Mistakes

  • Forgetting to add the WP_ALLOW_MULTISITE constant before installation.
  • Using a server block without the server_name including wildcard for subdomains.
  • Not updating wp-config.php with the network constants after enabling multisite.
  • Ignoring file permissions – Nginx needs read access to WordPress files, and PHP-FPM needs write access to uploads.
  • Not flushing permalinks after creating new sites.
  • Using relative URLs in themes/plugins that break across subsites.

Tips

  • Use a dedicated server block for each subdomain if you need custom SSL certificates or different roots.
  • Enable caching (like Nginx FastCGI cache or a plugin) to improve performance.
  • Back up both the database and the file system regularly – multisite databases can get large.
  • For subdomains, consider using a wildcard SSL certificate (e.g., Let’s Encrypt) to avoid separate certs.
  • Keep WordPress core, themes, and plugins updated from the network admin to avoid compatibility issues.
  • Test new sites in a staging environment before going live.

Troubleshooting

  • 404 errors on new sites: Check that your Nginx rewrite rules are correct. For subdirectories, ensure the try_files directive is set properly. Also, flush permalinks by visiting Settings → Permalinks in each site.
  • White screen of death: Check PHP error logs (/var/log/nginx/error.log and PHP-FPM logs). Often caused by missing PHP extensions or incorrect file permissions.
  • Subdomain not resolving: Verify DNS wildcard record. Use dig site1.example.com to see if it resolves.
  • Static files (CSS/JS) not loading: Ensure your Nginx config has a location block for static files, and that file permissions are correct (755 for directories, 644 for files).
  • Cannot access network admin: Check that DOMAIN_CURRENT_SITE is set correctly in wp-config.php. Also, ensure your wp-admin rewrite is working.
  • SSL issues: If using HTTPS, make sure all URLs use HTTPS (set FORCE_SSL_ADMIN and update site URLs). Also, configure Nginx to redirect HTTP to HTTPS.

Frequently Asked Questions

Can I switch from subdirectories to subdomains later?

It’s possible but not trivial. You’d need to move all sites and update the database. It’s easier to decide upfront.

Do I need a wildcard SSL certificate for subdomains?

Yes, or you’ll get browser warnings. Let’s Encrypt offers free wildcard certs.

How many sites can I have?

Practically, hundreds or thousands, but performance depends on your server resources and caching.

Can I use multisite for a client network?

Yes, but each site gets its own admin area. You can restrict plugins and themes via network settings.

What is the difference between subdomain and subdirectory multisite?

Subdomain sites have distinct domains (site1.example.com), while subdirectory sites share the domain with a path (example.com/site1). Subdomains are better for SEO if sites are independent, but require wildcard DNS and SSL.

How do I back up a multisite network?

Back up the entire database and the wp-content directory. Use tools like UpdraftPlus or manual mysqldump.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →