1

On our server www.example.com, we use the <Location> directive to proxy traffic to a back-end server:

<Location /app1>
  ProxyPass http://192.168.1.20
</Location>

Then we added a sub-domain uat.example.com which points to the same IP address of www.example.com. We want to use it as a proxy for client to test an app being developed. Hopefully, the client can access via:

http://uat.example.com/app2_uat

Now if we add a Location:

<Location /app2_uat>
  ProxyPass http://192.168.1.30
</Location>

The client can access both:

http://www.example.com/app2_uat
http://uat.example.com/app2_uat

How can I restrict Location such that only:

http://uat.example.com/app2_uat

Is accessible? (i.e. http://www.example.com/app2_uat should not be accessible.)

Giacomo1968
  • 3,542
  • 27
  • 38
ohho
  • 1,005
  • 8
  • 19
  • 34

1 Answers1

1

That’s easy to do if you use the NameVirtualHost option in Apache. I have a detailed answer provided for another user over here. The basic concept is you will be creating two different VirtualHost configs for each subdomain. Once you do that you can customize the configuration of both subdomains & achieve the granularity you are looking for.

EDIT: Adding details to how to setup NameVirtualHost for the original posters specific question details:

In general you need to first activate NameVirtualHost for the port you want. I will assume you will use port 80, so find this line in your Apache config—it might be in /etc/apache2/ports.conf—& set as so:

NameVirtualHost *:80

Make sure your Apache config—chances are the same /etc/apache2/ports.conf as above—is set to list to port 80. Which should be the case, but adding here for reference:

Listen 80

Here is where the magic happens. Again, I am just doing the bare-bones basics so adjust to whatever your server settings are. This is for www.example.com:

<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias www.example.com

  <Location /app1>
    ProxyPass http://192.168.1.20
  </Location>

</VirtualHost>

And now for uat.example.com create a new config like so:

<VirtualHost *:80>
  ServerName uat.example.com
  ServerAlias uat.example.com

  <Location /app2_uat>
    ProxyPass http://192.168.1.30
  </Location>

</VirtualHost>

By using NameVirtualHost you can setup two separate domain configs tied to one IP address. Again, please review the answer I linked to above for more details.

Giacomo1968
  • 3,542
  • 27
  • 38
  • Do you mean putting the `Location` block inside the `VirtualHost` block? Could you please put exact syntax in your answer? – ohho Nov 12 '13 at 03:36
  • Yes, place the `Location` block in the `VirtualHost` block. But you are creating two new configs. One for `www` and another for `uat`. Read my edited answer above. – Giacomo1968 Nov 12 '13 at 03:47