Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: How to define and use variables in httpd.conf |
|
Author |
|
adrian
Joined: 31 Mar 2011 Posts: 4
|
Posted: Thu 31 Mar '11 6:20 Post subject: How to define and use variables in httpd.conf |
|
|
Hey everybody,
I'm running Apache 2.2.17 on Windows, and I'm trying to create a configuration file that takes certain variables, whose values are set depending on whether the server is in a test or production environment.
For example, DocumentRoot will be different etc.
I'm looking for something as simple as:
Code: |
SetEnv DOCUMENT_ROOT /blah/blah/
...
DocumentRoot $(DOCUMENT_ROOT)
|
First of all that doesn't seem possible natively (although this seems like a fundamental feature).
I found mod_define that seems to enable this sort of functionality, but couldn't find the corresponding mod_define.so binary for Windows, and I don't know how to build it from the source code.
Any help will be appreciated.
adrian |
|
Back to top |
|
bentogoa

Joined: 09 Feb 2007 Posts: 66 Location: GOA
|
Posted: Thu 31 Mar '11 9:01 Post subject: |
|
|
wouldn't it be easy for you to use Virtual Host, here u can use different doc root for different sites |
|
Back to top |
|
adrian
Joined: 31 Mar 2011 Posts: 4
|
Posted: Thu 31 Mar '11 10:45 Post subject: |
|
|
Thanks for your answer.
DocumentRoot is in fact inside a <VirtualHost> directive, but I still need to be able to use a common value for DocumentRoot and many other <Directory> directives:
Code: |
SetEnv DOCUMENT_ROOT /blah/blah
<VirtualHost *:80>
DocumentRoot $(DOCUMENT_ROOT)
...
<Directory $(DOCUMENT_ROOT)/A>
....
</Directory>
<Directory $(DOCUMENT_ROOT)/B>
....
</Directory>
</VirtualHost>
|
adrian |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7407 Location: EU, Germany, Next to Hamburg
|
Posted: Thu 31 Mar '11 15:14 Post subject: |
|
|
What you need is mod_marco. The compiled binary can be found on the download page from apachelounge.
emaple
Code: |
## Define a VHost Macro.
<Macro VHost $host $port $dir>
Listen $port
<VirtualHost $host:$port>
DocumentRoot $dir
<Directory $dir>
# do something here...
</Directory>
# limit access to intranet subdir.
<Directory $dir/intranet>
order deny,allow
deny from all
allow from 10.0.0.0/8
</Directory>
</VirtualHost>
</Macro>
## Use of VHost with different arguments.
Use VHost www.apache.org 80 /projects/apache/web
Use VHost www.perl.com 8080 /projects/perl/web
Use VHost www.ensmp.fr 1234 /projects/mines/web
|
|
|
Back to top |
|
adrian
Joined: 31 Mar 2011 Posts: 4
|
Posted: Thu 31 Mar '11 16:30 Post subject: |
|
|
Yes, that makes sense. And split the conf in two files - location independent with the macro, and the location dependent part where I include the first file with the actual argument.
Code: |
include macros.conf
Use my_macro /blah/blah
|
Thanks!
adrian |
|
Back to top |
|
|
|
|
|
|