Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

nginx config that will work with subdomain multisite installation of Wordpress (Bedrock stack)

I need an nginx config that will work with a subdomain multisite installation of Wordpress (Bedrock stack).

The .htaccess that seemed to work was the following:

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) wp/$1 [L]
RewriteRule ^(.*.php)$ wp/$1 [L]
RewriteRule . index.php [L]

However, I'm looking for a solution preferably at the site definition level of the nginx configuration.

Note: This .htaccess allows me to avoid having the /wp/ subdirectory as well. This is also a capability I would like to have replicated.

To be clear, I'm using the Bedrock/WP-Skeleton file structure. https://github.com/roots/bedrock#folder-structure. Setting the webroot as /wp does not work. The answers below seem to be for typical nginx configurations - but this configuration specifically requires rewrites, as you can see in the .htaccess above.

As requested, this is my current nginx configuration for the site. I made some attempts to change it, but am providing the fresh one because nothing I was doing was working properly.

# WPSUBDOMAIN BASIC NGINX CONFIGURATION
server {

        # Uncomment The Following Line For Domain Mapping
        # listen 80 default_server;

        server_name domain.do *.domain.do;

        # Uncomment The Following Line For Domain Mapping
        server_name_in_redirect off;

        access_log   /var/log/nginx/domain.do.access.log rt_cache;
        error_log    /var/log/nginx/domain.do.error.log;

        root /var/www/domain.do/deployments/current/web;
        index index.php index.htm index.html;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ .php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass php;
        }

        include common/wpcommon.conf;
        include common/locations.conf;

}

and for good measure, this is the wpcommon.conf that is referenced above:

# WordPress Common Settings


# Limit Access To Avoid Brute Force Attack
location = /wp-login.php {
        limit_req zone=one burst=1 nodelay;
        include fastcgi_params;
        fastcgi_pass php;
}

# Disable wp-config.txt
location = /wp-config.txt {
        deny  all;
        access_log off;
        log_not_found off;
}

# Disallow PHP In Upload Folder
location /wp-content/uploads/ {
        location ~ .php$ {
                #Prevent Direct Access Of PHP Files From Web Browsers
                deny all;
        }
}
User Gravatar

etcook

Posted Mar 23 2014 17:58 UTC

$30


  • Assigned To etcook
  • Solved
  • wordpress
    apache
    nginx
  • 4611 Views

4 Replies


Hi,

here http://codex.wordpress.org/Nginx you can find the official snippet for all multisite installations.

In Nginx you cannot use .htacccess files by design. Here http://wiki.nginx.org/LikeApache-htaccess they explain why.

You can set the root to /wp and the rewrite will work as desired.

User Gravatar

fulippo

Posted Mar 24 2014 0:06 UTC

This post I added on my blog may be helpful for you as well. This is specific to Ajenti but for the most part has a lot of details and helpful information about using Nginx and configuration:

http://smyl.es/how-to-setup-a-wordpress-php-site-with-nginx-php5-fpm-using-ajenti-v/

User Gravatar

tripflex

Posted Mar 24 2014 12:26 UTC

Can you provide us your current Nginx configuration and i'll modify it to what you need?

User Gravatar

tripflex

Posted Mar 25 2014 7:10 UTC

Looks like these rules will likely work:

rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
User Gravatar

etcook

Posted Mar 25 2014 21:12 UTC

Solution

This didn't solve your task? Get your own custom solution.

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions