0

Recently migrated a multisite network, only to discover some of the sites are using a theme that's incompatible with the server's PHP version.

While I work on a longterm fix, what I'd like to is use NGINX to reverse proxy the non-working sites to the old server, while keeping the current, working sites pointed to the new server.

When I try the following, I'm able to make it to my old site's pages, but static assets (js, css, etc.) return 404, and I'm unable to access any /wp-admin pages. What should I change?

Here's the whole server block config. Save for the location /oldsite, I'm using this config for other server blocks as well. In this case all my WordPress files are stored in their own separate /wordpress/ directory, while /wp-content/ is kept in the root of each project.

In this case, these are subdirectory multisite installs.

server {
    server_name mydomain.com www.mydomain.com;

    root /var/www/html/wordpress/mydomain.com/wordpress/;

    location /oldsite {
        proxy_pass http://my.old.ip;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

     index index.php index.html;

     location /wp-content {
        root /var/www/html/wordpress/mydomain.com/;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        #If a file isnt found, 404
        try_files $uri =404;
        #Include Nginxs fastcgi configuration
        include /etc/nginx/fastcgi.conf;
    }

    if (!-e $request_filename) {
        # Don't use $uri here, see https://github.com/yandex/gixy/issues/77
        rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }

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

}
2

You also need to pass to your old server the directories corresponding to the old site's uploaded files and theme directories. And possibly plugin directories if they serve static content or have PHP files that are called directly rather than included within WordPress.

For example (uses regex, so not as efficient as it could be, but it's temporary, right?):

location ~ (/oldsite/|/wp-content/uploads/sites/5/|/wp-content/themes/oldsitetheme/) {
| improve this answer | |
  • Congratulations on the 200K. – user9517 Jun 30 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.