Possible to reverse proxy WP multisite to a separate server with NGINX?

user3183717 asked:

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$ {
        #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 ;


My answer:

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.

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/) {

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.