Support » Localhost Installs » Converting MS install from Apache2 to Nginx

  • Trying to move a working Apache2 config to Nginx and failing miserably. The structure is:
    / – root is something else, not wordpress
    /wordpress/ – the real folder with wordpress files, should not be accessed directly
    /about/ – a fake directory for one of the multi-sites
    /blog/ a fake directory for one of the multi-sites

    This is the Apache2 rule set that works:

    RewriteRule ^/(wp-(content|admin|includes).*) /wordpress/$1 [L]
    
            # MultiSites
            RewriteRule ^/about/(wp-(content|admin|includes).*) /wordpress/$1 [L]
            RewriteRule ^/about/(.*\.php)$ /wordpress/$1 [L]
            RewriteRule ^/about/(.*) /wordpress/index.php [L]
    
            RewriteRule ^/blog/(wp-(content|admin|includes).*) /wordpress/$1 [L]
            RewriteRule ^/blog/(.*\.php)$ /wordpress/$1 [L]
            RewriteRule ^/blog/(.*) /wordpress/index.php [L]
            RewriteRule ^/blog/tag/(.*)/ /wordpress/index.php [L]

    I’ve tried a whole bunch of things and not gotten anywhere. Right now I’m trying just:

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

    just to get *something* from WordPress as a starting point, but all I get is a 403 Forbidden. The file permissions are all readable by the server and directories and PHP scripts are executable. So I don’t think it’s a file system permission problem, but beyond that I don’t know what else to try.

    Any suggestions appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Update: I’ve updated WordPress to 3.9. When I remove all the wordpress rules from nginx, I can go to /wordpress/ and get the master blog, and I can also log in to the master blog an navigate through the control panel (mostly).

    Problem 1:
    In the master blog, sometimes the link goes to /wp-admin/network/ where it should really go to /wordpress/wp-admin/network/. On apache, this was fixed with:

    RewriteRule ^/(wp-(content|admin|includes).*) /wordpress/$1 [L]

    ….which just silently redirected to the right place.

    My attempt to do the same with Nginx:

    location ^~ ^/(wp-(content|admin|includes).*) {
    try_files /wordpress/$1 =404;
    }

    Produces a 500 response with the error: “rewrite or internal redirection cycle while internally redirecting to “/index.html””.

    Problem 2:

    I haven’t been able to make a rule set that does what the Apache rules did:

    RewriteRule ^/blog/(wp-(content|admin|includes).*) /wordpress/$1 [L]
    RewriteRule ^/blog/(.*\.php)$ /wordpress/$1 [L]
    RewriteRule ^/blog/(.*) /wordpress/index.php [L]
    RewriteRule ^/blog/tag/(.*)/ /wordpress/index.php [L]
    
    I also can't make it take precedent over the pattern rule:
    
    location ~ ^/([a-zA-Z0-9\-\_]+)/$ {
         try_files /cache/$1.html $uri $uri/ /other-index.php?rt=$1;
       }
    
    which is too greedy. I've tired using <code>^~</code> on the <code>/blog/</code> rule without success.

    I’d recommend taking a look at this Multisite nginx configuration: https://rtcamp.com/wordpress-nginx/tutorials/multisite/subdirectories/minimal/. It’s hard to tell what else you have in your virtual host that may be causing trouble. If that link is of no help perhaps you can share your entire virtual host via http://pastebin.com/.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Converting MS install from Apache2 to Nginx’ is closed to new replies.