Wordpress Multi-Site Converting Apache to Nginx

Francis Daly francis at daoine.org
Wed Apr 30 07:15:37 UTC 2014

On Tue, Apr 29, 2014 at 11:33:57PM -0400, Nick Rahl wrote:

Hi there,

> >That's not what ^~ means.
> The manual says, "If the longest matching prefix location has the
> "|^~|" modifier then regular expressions are not checked". Which
> means that a ^~ location will have a higher priority than a regular
> expression rule, right?


> location ^~ /wordpress/ {
>    try_files $uri /wordpress/index.php =404;
> }
> What I intend: "If the URL starts with "/wordpress/", then do not
> check any regular expression rules. Instead, load the requested URI
> directly."

Ok, so long as your idea of "load the requested uri" matches nginx's.

According to http://nginx.org/r/try_files, that should probably try to
send you the content of /usr/local/nginx/html/wordpress/index.php or 404.

> What happens: when visiting "wordpress/" I get a blank page.

What does

  curl -v http://whatever/wordpress/


Is your blank page a http 200 with no content, or a http 200 with some
content that the browser shows as blank, or some other http response?

> I have updated this rule to be a regex rule:
> llocation ~ ^/(wp-(content|admin|includes).*) {
>       try_files /wordpress/$1 /wordpress/$1/index.php =404;
>    }
> What I intend: "If /wp-content followed by anything, or /wp-admin
> followed by anything, or /wp-includes followed by anything: Silently
> (no browser redirect) show the same URL as if a /wordpress/
> directory were inserted in front. ie. "/wp-admin/bob" becomes
> "/wordpress/wp-admin/bob/", but does not do a redirect. If a
> directory, load index.php inside the given directoy."

try_files probably doesn't do what you think it does.

The final argument does an internal rewrite. The other arguments are
served as files in the current context, unless they end in "/" in which
case the "index" value is involved.

> What happens: I visit /wp-admin/ and get wp-admin.php, dumped as plain text.

  curl -v http://whatever/wp-admin/

The logs will show which location is used. Can you see which
file-on-the-filesystem wp-admin.php is returned?

(I don't see anything in your provided config which would associate
wp-admin.php with a request for /wp-admin/. I would have expected the
file /usr/local/nginx/html/wordpress/wp-admin/index.php to be returned.)

> It's not passing to PHP.

The initial request will have a "location" chosen.

A subrequest will have a "location" chosen.

"just serve this file" will not have a "location" chosen.

> But I have a PHP block:
> location ~ \.php$ {
>       try_files $uri =404;
>       fastcgi_split_path_info ^(.+\.php)(/.+)$;
>       fastcgi_index index.php;

For info: those two lines probably don't do anything useful here.

>       include fastcgi_params;
>       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
>       fastcgi_pass unix:/var/run/php5-fpm.sock;
> }
> So it should be passing to PHP?

Not unless there's a request or subrequest that best-matches this

Good luck with it,

Francis Daly        francis at daoine.org

More information about the nginx mailing list