You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ndmigration <nd...@gmail.com> on 2011/05/06 05:41:35 UTC

[users@httpd] Restrict subdirectory access based on host name

Hi,

We have two web servers under load balancer. I want to restrict access to
certain path based on host name. For example, 

1. www.sc.org 
2. www.sc.com

Both the above are pointing to the same Load Balacer IP but they need to
serve site from different folders. However, they should not serve site from
other folders.

www.sc.org should serve site from a folder called "cs"
www.sc.com should serve site from a folder called "dam"

but I don't want them to be interchangeable like www.sc.org/dam or
www.sc.com/cs. How to restric this?

Thanks,
Migration
-- 
View this message in context: http://old.nabble.com/Restrict-subdirectory-access-based-on-host-name-tp31555898p31555898.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Restrict subdirectory access based on host name

Posted by Yehuda Katz <ye...@ymkatz.net>.
On Fri, May 6, 2011 at 12:12 AM, Ndmigration <nd...@gmail.com> wrote:
>
> Thanks for your response. The below is what I currently have it. But, when
> I
> use www.sc.com/cs then I was able to access it. However, I would like to
> restrict it. So, only www.sc.org can go to cs folder, and www.sc.com can
> go
> to dam folder
>
> NameVirtualHost *:7777
>
> <VirtualHost *:7777>
>    DocumentRoot "/usr/local/apache/htdocs/cs"
>    ServerName www.sc.org
> </VirtualHost>
>
> <VirtualHost *:7777>
>    DocumentRoot "/usr/local/apache/htdocs/dam"
>    ServerName www.sc.com
> </VirtualHost>


You either:
1. Have folders "/usr/local/apache/htdocs/dam/cs" and
"/usr/local/apache/htdocs/cs/dam" and that is what you are seeing
2. Apache is not actually loading the virtual hosts.

- Yehuda

Re: [users@httpd] Restrict subdirectory access based on host name

Posted by Ndmigration <nd...@gmail.com>.
Hi,

Thanks for your response. The below is what I currently have it. But, when I
use www.sc.com/cs then I was able to access it. However, I would like to
restrict it. So, only www.sc.org can go to cs folder, and www.sc.com can go
to dam folder

NameVirtualHost *:7777

<VirtualHost *:7777>
    DocumentRoot "/usr/local/apache/htdocs/cs"
    ServerName www.sc.org
</VirtualHost>

<VirtualHost *:7777>
    DocumentRoot "/usr/local/apache/htdocs/dam"
    ServerName www.sc.com
</VirtualHost>



Yehuda Katz wrote:
> 
> On Thu, May 5, 2011 at 11:41 PM, Ndmigration <nd...@gmail.com>
> wrote:
> 
>> www.sc.org should serve site from a folder called "cs"
>> www.sc.com should serve site from a folder called "dam"
>>
>> but I don't want them to be interchangeable like www.sc.org/dam or
>> www.sc.com/cs. How to restric this?
>>
> 
> Are they in a NameVirtualHost or the default site for the IP?
> If they are in one named vhosts, you could separate it into two and use
> directory/location directives in the vhost config.
> You could also make them vhosts now even though they weren't before.
> 
> Otherwise, I would suggest mod_rewrite.
> Something like this might work (although I did not test it)
> 
>> RewriteCond %{HTTP_HOST} !^www\.sc\.com [NC]
>> RewriteCond %{HTTP_HOST} !^$
>> RewriteRule ^dam/?(.*) - [F]
>>
> 
> 
> RewriteCond %{HTTP_HOST} !^www\.sc\.org [NC]
>> RewriteCond %{HTTP_HOST} !^$
>> RewriteRule ^cs/?(.*) - [F]
> 
> 
> - Yehuda
> 
> 

-- 
View this message in context: http://old.nabble.com/Restrict-subdirectory-access-based-on-host-name-tp31555898p31555998.html
Sent from the Apache HTTP Server - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Restrict subdirectory access based on host name

Posted by Yehuda Katz <ye...@ymkatz.net>.
On Thu, May 5, 2011 at 11:41 PM, Ndmigration <nd...@gmail.com> wrote:

> www.sc.org should serve site from a folder called "cs"
> www.sc.com should serve site from a folder called "dam"
>
> but I don't want them to be interchangeable like www.sc.org/dam or
> www.sc.com/cs. How to restric this?
>

Are they in a NameVirtualHost or the default site for the IP?
If they are in one named vhosts, you could separate it into two and use
directory/location directives in the vhost config.
You could also make them vhosts now even though they weren't before.

Otherwise, I would suggest mod_rewrite.
Something like this might work (although I did not test it)

> RewriteCond %{HTTP_HOST} !^www\.sc\.com [NC]
> RewriteCond %{HTTP_HOST} !^$
> RewriteRule ^dam/?(.*) - [F]
>


RewriteCond %{HTTP_HOST} !^www\.sc\.org [NC]
> RewriteCond %{HTTP_HOST} !^$
> RewriteRule ^cs/?(.*) - [F]


- Yehuda