Mailing List Archive

Variable of document root path based on source ip
I'm trying to set a virtual host on apache2 with this configuration.

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

<If "-R '192.168.1.0/24'">
Define directory_path /srv/http/mysite
</If>
<Else>
Define directory_path /srv/http/under_construction
</Else>

DocumentRoot ${directory_path}

<Directory ${directory_path}>
Require all granted
</Directory>
</VirtualHost>

The problem is that the If directive does not match when I access it
from that lan.

I'm using Apache/2.4.18.

--
Ivan Ionu?

Str. S?li?te 20, Galati 800023

Tel/Fax: +40236 493277

Email: ivan.ionut@tehnopol-gl.ro

_The content of this email is confidential and intended for the
recipient specified in message only. It is strictly forbidden to share
any part of this message with any third party, without a written consent
of the sender. If you are not the intended recipient of this message,
please notify the sender immediately, and delete the message and any
attachments. Any disclosure, reproduction, distribution or other use of
this message or any attachments by an individual or entity other than
the intended recipient is prohibited._
Re: Variable of document root path based on source ip [ In reply to ]
You cannot use Define conditionally this way. It is parsed at startup and
ignores any enclosing directives

On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:

> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com
> ServerAlias www.mysite.com
>
> <If "-R '192.168.1.0/24'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it from
> that lan.
>
> I'm using Apache/2.4.18.
> --
>
> *Ivan Ionu?*
>
> *Str. S?li?te 20, Galati 800023*
>
> *Tel/Fax: +40236 493277 *
>
> *Email: ivan.ionut@tehnopol-gl.ro <ivan.ionut@tehnopol-gl.ro>*
>
>
>
>
> *The content of this email is confidential and intended for the recipient
> specified in message only. It is strictly forbidden to share any part of
> this message with any third party, without a written consent of the
> sender. If you are not the intended recipient of this message, please
> notify the sender immediately, and delete the message and any attachments.
> Any disclosure, reproduction, distribution or other use of this message or
> any attachments by an individual or entity other than the intended
> recipient is prohibited.*
>
>
>
Re: Variable of document root path based on source ip [ In reply to ]
The simple approach here would be to define separate IP:80 vhosts and set a
separate document root in each vhost.

On Mon, 2 May 2022 at 06:48, Eric Covener <covener@gmail.com> wrote:

> You cannot use Define conditionally this way. It is parsed at startup and
> ignores any enclosing directives
>
> On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
>
>> I'm trying to set a virtual host on apache2 with this configuration.
>>
>> <VirtualHost *:80>
>> ServerName mysite.com
>> ServerAlias www.mysite.com
>>
>> <If "-R '192.168.1.0/24'">
>> Define directory_path /srv/http/mysite
>> </If>
>> <Else>
>> Define directory_path /srv/http/under_construction
>> </Else>
>>
>> DocumentRoot ${directory_path}
>>
>> <Directory ${directory_path}>
>> Require all granted
>> </Directory>
>> </VirtualHost>
>>
>> The problem is that the If directive does not match when I access it from
>> that lan.
>>
>> I'm using Apache/2.4.18.
>> --
>>
>> *Ivan Ionu?*
>>
>> *Str. S?li?te 20, Galati 800023*
>>
>> *Tel/Fax: +40236 493277 *
>>
>> *Email: ivan.ionut@tehnopol-gl.ro <ivan.ionut@tehnopol-gl.ro>*
>>
>>
>>
>>
>> *The content of this email is confidential and intended for the recipient
>> specified in message only. It is strictly forbidden to share any part of
>> this message with any third party, without a written consent of the
>> sender. If you are not the intended recipient of this message, please
>> notify the sender immediately, and delete the message and any attachments.
>> Any disclosure, reproduction, distribution or other use of this message or
>> any attachments by an individual or entity other than the intended
>> recipient is prohibited.*
>>
>>
>>
>
Re: Variable of document root path based on source ip [ In reply to ]
I did not understand... I have to define two vhosts configs for
mysite.com with two separate document root in each config?

PS: i have one static ip for mysite.com [1]

On 03-05-2022 00:32, Frank Gingras wrote:

> The simple approach here would be to define separate IP:80 vhosts and
> set a separate document root in each vhost.
>
> On Mon, 2 May 2022 at 06:48, Eric Covener <covener@gmail.com> wrote:
> You cannot use Define conditionally this way. It is parsed at startup
> and ignores any enclosing directives
>
> On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro>
> wrote:
>
> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com [1]
> ServerAlias www.mysite.com [2]
>
> <If "-R '192.168.1.0/24 [3]'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it
> from that lan.
>
> I'm using Apache/2.4.18. [4]
>
> --
> Ivan Ionu?
>
> Str. S?li?te 20, Galati 800023
>
> Tel/Fax: +40236 493277
>
> Email: ivan.ionut@tehnopol-gl.ro
>
> _The content of this email is confidential and intended for the
> recipient specified in message only. It is strictly forbidden to share
> any part of this message with any third party, without a written
> consent of the sender. If you are not the intended recipient of this
> message, please notify the sender immediately, and delete the message
> and any attachments. Any disclosure, reproduction, distribution or
> other use of this message or any attachments by an individual or entity
> other than the intended recipient is prohibited._


Links:
------
[1] http://mysite.com
[2] http://www.mysite.com
[3] http://192.168.1.0/24
[4] http://2.4.18.
Re: Variable of document root path based on source ip [ In reply to ]
Do all clients come from the 192.168.1.0/24 range?

On Tue, 3 May 2022 at 04:23, Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:

> I did not understand... I have to define two vhosts configs for mysite.com
> with two separate document root in each config?
>
>
> PS: i have one static ip for mysite.com
>
> On 03-05-2022 00:32, Frank Gingras wrote:
>
> The simple approach here would be to define separate IP:80 vhosts and set
> a separate document root in each vhost.
>
> On Mon, 2 May 2022 at 06:48, Eric Covener <covener@gmail.com> wrote:
>
> You cannot use Define conditionally this way. It is parsed at startup and
> ignores any enclosing directives
>
> On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
>
> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com
> ServerAlias www.mysite.com
>
> <If "-R '192.168.1.0/24'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it from
> that lan.
>
> I'm using Apache/2.4.18.
> --
>
> *Ivan Ionu?*
>
> *Str. S?li?te 20, Galati 800023*
>
> *Tel/Fax: +40236 493277 *
>
> *Email: ivan.ionut@tehnopol-gl.ro <ivan.ionut@tehnopol-gl.ro>*
>
>
>
>
> *The content of this email is confidential and intended for the recipient
> specified in message only. It is strictly forbidden to share any part of
> this message with any third party, without a written consent of the
> sender. If you are not the intended recipient of this message, please
> notify the sender immediately, and delete the message and any attachments.
> Any disclosure, reproduction, distribution or other use of this message or
> any attachments by an individual or entity other than the intended
> recipient is prohibited.*
>
>
>
>
Re: Variable of document root path based on source ip [ In reply to ]
On Mon, May 2, 2022 at 8:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
>
> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com
> ServerAlias www.mysite.com
>
> <If "-R '192.168.1.0/24'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it from that lan.

Possibly something like this could work:

Define directory_path_mysite "/srv/http/mysite"
Define directory_path_under_construction "/srv/http/under_construction"
<VirtualHost *:80>
<If "-R '192.168.1.0/24'">
DocumentRoot "${directory_path_mysite}"
<Else>
DocumentRoot "$(directory_path_under_construction}"
</If>
<Directory "${directory_path_mysite}">
Require all granted
</Directory>
<Directory "${directory_path_under_construction}">
Require all granted
</Directory>
</VirtualHost>

Both DocumentRoots would be initialized at startup (when Defines are
evaluated, the <Directory paths must be known then), while the
DocumentRoot used at runtime will be determined based on the <If
still.


Regards;
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Variable of document root path based on source ip [ In reply to ]
On Tue, May 3, 2022 at 5:44 PM Yann Ylavic <ylavic.dev@gmail.com> wrote:
>
> On Mon, May 2, 2022 at 8:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
> >
> > I'm trying to set a virtual host on apache2 with this configuration.
> >
> > <VirtualHost *:80>
> > ServerName mysite.com
> > ServerAlias www.mysite.com
> >
> > <If "-R '192.168.1.0/24'">
> > Define directory_path /srv/http/mysite
> > </If>
> > <Else>
> > Define directory_path /srv/http/under_construction
> > </Else>
> >
> > DocumentRoot ${directory_path}
> >
> > <Directory ${directory_path}>
> > Require all granted
> > </Directory>
> > </VirtualHost>
> >
> > The problem is that the If directive does not match when I access it from that lan.
>
> Possibly something like this could work:
>
> Define directory_path_mysite "/srv/http/mysite"
> Define directory_path_under_construction "/srv/http/under_construction"
> <VirtualHost *:80>
> <If "-R '192.168.1.0/24'">
> DocumentRoot "${directory_path_mysite}"
> <Else>
> DocumentRoot "$(directory_path_under_construction}"
> </If>

But DocumentRoot might not be allowed in an <If section..

> <Directory "${directory_path_mysite}">
> Require all granted
> </Directory>
> <Directory "${directory_path_under_construction}">
> Require all granted
> </Directory>
> </VirtualHost>
>
> Both DocumentRoots would be initialized at startup (when Defines are
> evaluated, the <Directory paths must be known then), while the
> DocumentRoot used at runtime will be determined based on the <If
> still.
>
>
> Regards;
> Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Variable of document root path based on source ip [ In reply to ]
No, I have clients that from wan too. Basically when I make some
important changes to a site...all clients from wan to view the
under_construction directory.

On 03-05-2022 16:03, Frank Gingras wrote:

> Do all clients come from the 192.168.1.0/24 [1] range?
>
> On Tue, 3 May 2022 at 04:23, Ivan Ionut <ivan.ionut@tehnopol-gl.ro>
> wrote:
>
> I did not understand... I have to define two vhosts configs for
> mysite.com [2] with two separate document root in each config?
>
> PS: i have one static ip for mysite.com [2]
>
> On 03-05-2022 00:32, Frank Gingras wrote:
>
> The simple approach here would be to define separate IP:80 vhosts and
> set a separate document root in each vhost.
>
> On Mon, 2 May 2022 at 06:48, Eric Covener <covener@gmail.com> wrote:
> You cannot use Define conditionally this way. It is parsed at startup
> and ignores any enclosing directives
>
> On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro>
> wrote:
>
> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com [2]
> ServerAlias www.mysite.com [3]
>
> <If "-R '192.168.1.0/24 [1]'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it
> from that lan.
>
> I'm using Apache/2.4.18. [4]
>
> --
> Ivan Ionu?
>
> Str. S?li?te 20, Galati 800023
>
> Tel/Fax: +40236 493277
>
> Email: ivan.ionut@tehnopol-gl.ro
>
> _The content of this email is confidential and intended for the
> recipient specified in message only. It is strictly forbidden to share
> any part of this message with any third party, without a written
> consent of the sender. If you are not the intended recipient of this
> message, please notify the sender immediately, and delete the message
> and any attachments. Any disclosure, reproduction, distribution or
> other use of this message or any attachments by an individual or entity
> other than the intended recipient is prohibited._


Links:
------
[1] http://192.168.1.0/24
[2] http://mysite.com
[3] http://www.mysite.com
[4] http://2.4.18.
Re: Variable of document root path based on source ip [ In reply to ]
A blunt approach could also leverage mod_rewrite, but I would test Yann's
suggestion. You can rewrite the path to the filesystem provided that the
RewriteRule is in the vhost context.

On Tue, 3 May 2022 at 12:57, Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:

> No, I have clients that from wan too. Basically when I make some important
> changes to a site...all clients from wan to view the under_construction
> directory.
>
>
>
> On 03-05-2022 16:03, Frank Gingras wrote:
>
> Do all clients come from the 192.168.1.0/24 range?
>
> On Tue, 3 May 2022 at 04:23, Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
>
> I did not understand... I have to define two vhosts configs for mysite.com
> with two separate document root in each config?
>
>
> PS: i have one static ip for mysite.com
>
> On 03-05-2022 00:32, Frank Gingras wrote:
>
> The simple approach here would be to define separate IP:80 vhosts and set
> a separate document root in each vhost.
>
> On Mon, 2 May 2022 at 06:48, Eric Covener <covener@gmail.com> wrote:
>
> You cannot use Define conditionally this way. It is parsed at startup and
> ignores any enclosing directives
>
> On Mon, May 2, 2022, 2:24 AM Ivan Ionut <ivan.ionut@tehnopol-gl.ro> wrote:
>
> I'm trying to set a virtual host on apache2 with this configuration.
>
> <VirtualHost *:80>
> ServerName mysite.com
> ServerAlias www.mysite.com
>
> <If "-R '192.168.1.0/24'">
> Define directory_path /srv/http/mysite
> </If>
> <Else>
> Define directory_path /srv/http/under_construction
> </Else>
>
> DocumentRoot ${directory_path}
>
> <Directory ${directory_path}>
> Require all granted
> </Directory>
> </VirtualHost>
>
> The problem is that the If directive does not match when I access it from
> that lan.
>
> I'm using Apache/2.4.18.
> --
>
> *Ivan Ionu?*
>
> *Str. S?li?te 20, Galati 800023*
>
> *Tel/Fax: +40236 493277 *
>
> *Email: ivan.ionut@tehnopol-gl.ro <ivan.ionut@tehnopol-gl.ro>*
>
>
>
>
> *The content of this email is confidential and intended for the recipient
> specified in message only. It is strictly forbidden to share any part of
> this message with any third party, without a written consent of the
> sender. If you are not the intended recipient of this message, please
> notify the sender immediately, and delete the message and any attachments.
> Any disclosure, reproduction, distribution or other use of this message or
> any attachments by an individual or entity other than the intended
> recipient is prohibited.*
>
>
>
>