Nginx and Wordpress side-by-side with static directory alias?

Posted by user117161 on Server Fault See other posts from Server Fault or by user117161
Published on 2012-04-11T16:31:08Z Indexed on 2012/04/11 17:32 UTC
Read the original article Hit count: 171

Filed under:
|
|
|
|

I'm a Nginx novice, but I have it set up with Wordpress Multisite (subdirectories) and php-fpm, and it's working great as is. This lets me set up Wordpress sites off the web root:

domain.com/site1 - a Wordpress network single site, which renders as expected.
domain.com/site2 - ditto

etc.

Concurrently, I can easily create static files in the web root that don't conflict or interact with Wordpress, and they are also rendered normally.

domain.com/hello.html - rendered normally
domain.com/hello.php - rendered normally, including php processing
domain.com/static/hello.php - rendered normally (along as "static" isn't a WP single site name)

What I'd like to do, and this is where I'm out of my depth with nginx.conf, is create a root directory

domain.com/static

and put static sites in there

domain.com/static/site3
domain.com/static/site4

and have Nginx check the request that comes into the root

request comes in for: domain.com/site3

and before handing off to Wordpress, check to see if it exists in the /static folder

checks: domain.com/static/site3 - static content exists there

and if so, serves that content while maintaining the root URI.

serves: domain.com/site3 (with content from domain.com/static/site3)

if not, it lets Wordpress check if /site3 is a Wordpress single network site as it does now, and the process continues normally.

In nginx.conf, in the server section, I start with this try_files rule:

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

I then include a bunch of Wordpress specific rules as identified at http://codex.wordpress.org/Nginx under the subdirectory section.

I can see that rewrite rules might take care of it easily, but in my experimentation I've only achieved a bunch of looping (/static/static/static, etc.) and managed to bypass Wordpress if the looping stopped. Sorry if this is a very long-winded way of asking a simple question, but I'm definitely learning some of this stuff for the first time.

Thanks!

© Server Fault or respective owner

Related posts about php

Related posts about nginx