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
|
1 Answer
Reset to default 0I'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
location
block takes over this one on requests for static assets. Can you show your fullserver
block? You can omit all confidential info like domain names etc. – Ivan Shatsky Commented Jun 30, 2020 at 6:58