【问题标题】:How to have a Wordpress site on foo.example, and another Wordpress site on foo.example/bar?如何在 foo.example 上有一个 Wordpress 站点,在 foo.example/bar 上有另一个 Wordpress 站点?
【发布时间】:2018-09-27 22:12:28
【问题描述】:

我有一个仅在 PHP 5.2 中运行的旧版 WordPress 博客(在以后的版本中有很多不兼容性),我正在开发一个应该在 PHP 7 中运行的新 Wordpress 博客。

要求新博客的 URL 为 foo.example,而旧博客的 URL 为 foo.example/bar

由于 PHP 版本不同,每个版本都托管在不同的机器上。到目前为止,我得到的最接近的是有一个子域 bar.foo.example 指向旧博客,但不能让 foo.example/bar 做同样的事情(甚至不知道这是否可能)。

我很乐意为这项任务提供一些帮助,并且我愿意接受新的替代方案。

【问题讨论】:

  • 您需要了解 DNS 解析只对主机名而不是路径进行操作,因此foo.examplefoo.example/bar 将到达同一主机。在那里,可以将主机配置为将路径之一重定向或代理到另一台主机。

标签: php wordpress dns subdomain web-hosting


【解决方案1】:

根据您的服务器软件,我知道您可以在 NGINX 中执行类似的操作:

server {
    server_name domain.tld;
    root /var/www/wordpress;

    index index.php;

    ...

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

    location /bar/ {
            root /var/www/wordpress-legacy;
            try_files $uri $uri/ /index.php?$args;
    }


    ...
}

【讨论】:

    【解决方案2】:

    您不能真正根据请求路径指向不同的服务器 - 域将始终指向一台服务器(至少从用户角度来看)。但是,这台服务器可以用作代理并从正确的服务器提供内容。潜在的解决方案:

    1. 在这两台服务器前面放置一个负载平衡器 - 请参阅 HAProxy - URL Based routing with load balancing
    2. 将新服务器配置为代理,为子目录提供来自旧服务器的内容。例如使用NGINX Reverse Proxy:

      location /bar/ {
          proxy_pass http://legacy.foo.example/bar/;
      }
      

    【讨论】:

      猜你喜欢
      • 2011-12-02
      • 1970-01-01
      • 2018-06-15
      • 2017-04-14
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2018-01-30
      相关资源
      最近更新 更多