When enabling WordPress Multisite, configuration issues often arise, particularly when mixing subdirectories, subdomains, or DNS settings. Below are steps to ensure your setup works properly with NGINX, BIND, and WordPress Multisite:
1. DNS Configuration: Internal vs. External IP
- External IP: If users from the internet need access, BIND should point to the external IP of your server.
- Internal IP: Use this only if the server is accessed strictly within a private network.
For WordPress Multisite:
- For subdomain-based multisite, each subdomain (e.g.,
sub1.example.com
) must have a DNS A
or CNAME
record pointing to the external IP of your server.
- For subdirectory-based multisite, DNS settings remain the same as the primary domain (e.g.,
example.com
).
2. NGINX Configuration for WordPress Multisite
The primary NGINX configuration should handle both subdomains and subdirectories:
Base Configuration:
server {
listen 80;
server_name example.com *.example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.3-fpm.sock; # Adjust PHP socket or port
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|otf|ttc|webp|avif|mp4|webm|ogg|ogv|pdf|doc|docx|ppt|pptx|xls|xlsx|zip|rar|7z|tar|gz|bz2|txt|xml|rss|atom|json|vtt|srt)$ {
expires max;
log_not_found off;
}
}
Specific for Subdirectory-based Multisite:
location /subdirectory/ {
index index.php;
try_files $uri $uri/ /subdirectory/index.php?q=$uri&$args;
}
3. Updating BIND
for Subdomains
- Add
A
records for each subdomain. For wildcard subdomains:
*.example.com. IN A 288.218.198.981 # Replace with your external IP
- Reload BIND:
sudo systemctl reload named
4. Generalizing NGINX to Avoid Frequent Edits
You can create a generic configuration for subdomains or subdirectories:
For Subdomains:
server {
listen 80;
server_name ~^(?<subdomain>.+)\.example\.com$;
root /var/www/html/$subdomain;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
For Subdirectories:
Modify /etc/nginx/sites-available/example.com
to:
server {
listen 80;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ ^/([_0-9a-zA-Z-]+/) {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
}
5. Changing NGINX Listen Directive
Replace:
listen 288.218.198.981:80;
With:
listen 80;
If you have multiple IPs and want NGINX to listen on all available IPs, this configuration works universally.
6. WordPress Multisite Setup
- For Subdomain Multisite:
- In the WordPress admin, go to Tools > Network Setup.
- Select Subdomains and install the network.
- For Subdirectory Multisite:
- Use the subdirectory-based configuration and ensure your primary NGINX block matches the
DocumentRoot
.
7. Debugging Common Issues
Multisite Redirects to Another Site
- Ensure
wp-config.php
contains the correct multisite configuration:
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true); // Set to 'false' for subdirectory
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
- Remove browser cache to clear old redirects.
- Update the NGINX cache (if applicable):
sudo nginx -s reload
Subdomains Not Resolving
- Check DNS settings and verify wildcard
A
record is present.
- Ensure your server has access to handle requests for all subdomains.
Subdirectories Returning 404 Errors
- Confirm
.htaccess
or NGINX rules for pretty permalinks are correctly configured:
sudo systemctl reload nginx
8. Testing
After applying these changes:
- Use
curl
or a browser to test subdomains and subdirectories.
- Check logs for troubleshooting:
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
Let me know if any issues persist!