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

Recently migrated a multisite network, only to discover some of the sites are using a theme that's incompatible wit

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.

server {
    server_name mydomain www.mydomain;

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

    location /oldsite {
        proxy_pass ;
        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/;
    }

    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 
        rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }

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

}

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.

server {
    server_name mydomain www.mydomain;

    root /var/www/html/wordpress/mydomain/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/;
    }

    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/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 ;
    }

}
Share Improve this question edited Jun 30, 2020 at 15:22 user3183717 asked Jun 30, 2020 at 1:32 user3183717user3183717 2313 silver badges12 bronze badges 3
  • Most likely some other location block takes over this one on requests for static assets. Can you show your full server block? You can omit all confidential info like domain names etc. – Ivan Shatsky Commented Jun 30, 2020 at 6:58
  • Maybe worth also posting to SO/serverfault as it feels like more of an nginx quesiton than WP? – mozboz Commented Jun 30, 2020 at 9:41
  • @IvanShatsky I updated to show the full server block – user3183717 Commented Jun 30, 2020 at 15:23
Add a comment  | 

1 Answer 1

Reset to default 0

I'm not sure if it works first time, but lets try.

server {
    server_name mydomain www.mydomain;

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

    # The "^~" modifier makes this location to take priority over regex-matched locations
    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/;
    }

    location ~ \.php$ {
        # This rule now goes here, "last" changed to "break" to not leave this location after rewriting URI
        rewrite ^(/[^/]+)?(/.*\.php) $2 break;

        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;
    }

    location / {
        # Two other rewriting rules goes inside the root location block to not interfere with "location ^~ /oldsite { ... }"
        if (!-e $request_filename) {
            # Don't use $uri here, see https://github/yandex/gixy/issues/77
            rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
            rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        }

        try_files $uri $uri/ /index.php$is_args$args;
    }

}

I comment the changes I've made to your config.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742305187a4418795.html

相关推荐

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

    Recently migrated a multisite network, only to discover some of the sites are using a theme that's incompatible wit

    21小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信