Search code examples
javaapacheamazon-web-servicesnginxwebserver

How to configure two Web Application Pointing to one Host Name in Apache or NGiNX


Background, Our customer is Multi-Level Marketing Company (eCommerce Site) they will do business in most of the countries and currently we are migrating only two countries to new UI and rest all countries should be able to access Legacy Site. (We are working on to improve the Corporate Site with new UI look and some improved logic)

We have a requirement where we should point two separate web application (running in two webservers it can be Apache or NGINX) pointing to the same hostname based on sub directly we should split the traffic to the specific web application,

example:

 www.hostname.com/country1 --> should point to New Application
 www.hostname.com/country2 --> should point to New Application
 www.hostname.com/country3 --> should point to Legacy Application
 www.hostname.com/country4 --> should point to Legacy Application
 ..
 ..
 so on

Note: - We are using AWS and platform is Java and CMS in the background.

How can we achieve this?

Please help me out, Thanks in Advance.


Solution

  • What you're looking for is URI routing. This is typically a function you can find with most CDNs and API Gateways. Since you're on AWS you have a few options. The first option is to just use CloudFront natively to handle this. Here is a good tutorial on this topic -

    https://www.linkedin.com/pulse/how-use-amazon-cloudfront-application-router-chris-iona/

    Additionally, you can use AWS API Gateway. AWS API Gateway is just an abstraction on top of CloudFront. The main reason you might use API Gateway over CloudFront is for things like authorization with AWS services such as Cognito. It doesn't sound like this is a requirement for you so I would suggest sticking with the CloudFront solution.