有没有可能将代理WP MULTISE反向转换为具有Nginx的单独服务器?

时间:2020-06-30 作者:user3183717

最近迁移了一个多站点网络,却发现一些站点使用的主题与服务器的PHP版本不兼容。

虽然我正在进行长期修复,但我希望使用NGINX将非工作站点反向代理到旧服务器,同时保持当前工作站点指向新服务器。

当我尝试以下操作时,我能够访问旧站点的页面,但静态资产(js、css等)返回404,并且我无法访问任何/wp管理页面。我应该改变什么?

这是整个服务器块配置。保存为location /oldsite, 我也将此配置用于其他服务器块。在这种情况下,我的所有WordPress文件都存储在各自独立的/wordpress/ 目录,而/wp-content/ 保存在每个项目的根目录中。

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

}

1 个回复
SO网友:Ivan Shatsky

我不确定它第一次是否有效,但让我们试试。

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

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

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

}
我对您的配置所做的更改进行注释。

相关推荐

Nginx Serve WordPress从子路径404出现故障,如何修复?

我希望在发布到生产之前,宿主审查分支以进行暂存、测试并获得反馈。我试图遵循一些在线提供的文档,如NGINX配方(https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ ) 没有成功!那么,如何修复它呢?审查分支的模式是/review-xxxxx 或/review-xx_x-xxx. 因为我已经设置了部署管道,以触发发布到AWS ECSreview-* 分支,这是我想保密的地方,仅供测试和反馈使用。我打字很难/review-c