0

We have a working website under the domain x.domain.tld. We want to add a wordpress to it in such way we have x.domain.tld/blog but install it on another server so we don't touch anything on this old (but working) one.

So can i start a new server, install wordpress on it, have an apache rediretion on x.domain.tld/blog to redirect to the new server IP WHILE keeping the domain name in the url for the clients ?

That doesn't look doable to me. And we're reluctant migrating the whole old application to a new server. Is there another way of doing it ?

Thank you for your help

  • You can redirect the URL path www.example.com/blog to a different URL on (sub-) domain such as blog.example.com/latest with a [Redirect](https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect) directive. `Redirect /blog http://blog.example.com/latest` Or alternatively you can use Apache mod_proxy to reverse proxy the URL path and create a single URI space where Apache pulls in content from a different back end server. See https://serverfault.com/q/561892/546643 for some examples – Bob Jan 22 '21 at 15:39

2 Answers2

0

I think same as you.

The host part of a URL is determined by the client side.
If the host part of URLs are same (x.domain.tld and x.domain.tld), client will always connect to the same IP address for them.
It means if the host part is shared between apps, they should be served by the same host and/or IP address (as @HermanB commented, mod_proxy is technique that the first host receives the request from a client and gets the content from other host then combines the contents as if it is on the first host. With this, the client always connect to the first host.).

In contrast, we can let single host services multiple URL host and/or IP addresses (cf X.domain.tld and Y.domain.tld by a single host) using VirtualHost.

0

This is a perfectly valid case for reverse proxying. I linked to Nginx web site for explanation, because Nginx is very good at reverse proxying, but Apache with mod_proxy and mod_proxy_http will also work perfectly.

There are plenty of questions with high quality answers on this topic here; @HermanB linked one of them, but I suggest you to also search for others.

Basically, this task is accomplished with just the following in the VirtualHost:

<VirtualHost *:80>
   ServerName x.domain.tld
   ...
   ProxyPass /blog/  http://blog.domain.tld/blog/
   ProxyPassReverse /blog/  http://blog.domain.tld/blog/
</VirtualHost>

Such config can be applied in addition to "main site", i.e. everything not under the /blog/ URI would be served as before, as if there were no proxy directives.

As it is evident from the config snippet, the blog itself is must be installed to the web server blog.domain.tld so to be available under the path blog. I strongly recommend this approach, it must be not rebased (i.e. the same URI base /blog/ must be used on both servers); this way you will easily circumvent some hard to tackle problems, which arise from the fact reverse proxies usually don't rewrite URLs in proxied data. And be sure your application (Wordpress) generates all internal links only using relative URIs.

Nikita Kipriyanov
  • 8,033
  • 1
  • 21
  • 39