-1

www.example.com is on server01 with IP address 192.0.2.123

abc.example.com is on server02 with IP address 192.0.2.21

I actually do not want the subdomain abc. Ideally I want it at www.example.com/abc. I want to have a more cohesive website for usability and aesthetics. For non-technical people, having the content in a sub-directory feels that you are still on the same site compared to going to a sub-domain.

My problem is that the code for the subdomain site (Site2) is on server02 with a different IP. I cannot use just 1 server for the 2 sites: Site1 is using Apache, MySql, and PHP for PHP websites and static websites. Site 2 is a webapp that uses nginx, ruby and postgresql. Maintenance wise, IMHO, it is easiest to have site02 on a separate server. But as I said, it would be great if it can be visited by the end-user in a sub-directory of the main domain.

Is there a a way for me to achieve this?

2

In order for two servers to share the exact same domain (www.example.com) and your website to work properly the two servers would need to be a mirror of eachother in terms of content and functionality, ideally linked to the same databases and storage behind the scenes since the same user may access either server within the same session. This would be setup by creating an A DNS record for each server IP address for the subdomain www.

This isn't what you're after however since your servers have different functionality and software environment. This kind of routing cannot be done with a subfolder unfortunately.

Two potential solutions for you to consider:

  • You could setup some kind of proxy script on server01 which essentially forwards incoming requests onto server02 and then forwards the responses from server02 back to the requesting connection. This would technically achieve what you want but you'll be making server01 do more processing than should be required.

  • You could setup a redirection script in the subfolder on server01 so that if your end-users enter https://www.example.com/abc or https://www.example.com/abc/ into their browser address bar your script then redirects them automatically to https://abc.example.com/. For this you could return the HTTP header: HTTP/1.0 301 Location: http://abc.example.com/ using whichever scripting language you prefer and that works on server01.

|improve this answer|||||
  • Specifically "some kind of proxy" would be a "reverse proxy". Both Apache and Nginx can easily be configured as a reverse proxy to show content from another server. – Stephen Ostermiller Jan 14 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.