Forum Moderators: phranque

Message Too Old, No Replies

Using variables within virtualhost containers?

Can't figure out how to set a domain name as a variable and use it

         

davistv

4:15 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



I would like to reduce the opportunity for errors in my httpd.conf file, typos on domain names are the prime culprit. So I'd like to set a variable at the top of each VirtualHost container for the primary domain, then use that variable throughout the rest of the VirtualHost to configure the site.

So far, I haven't figured out how to do this. Here's what I've got so far, is this possible?

Thank You,
Troy

<VirtualHost *:80> 
SetEnv PRIMARY_DOMAIN test.com
DocumentRoot /w3/${PRIMARY_DOMAIN}/
ServerName ${PRIMARY_DOMAIN}
DirectoryIndex index.html
CustomLog logs/${PRIMARY_DOMAIN}_access_log combined
ErrorLog logs/${PRIMARY_DOMAIN}_error_log
ScriptAlias /cgi-bin/ /w3/${PRIMARY_DOMAIN}/cgi-bin/
<Directory /w3/${PRIMARY_DOMAIN}/cgi-bin>
...
</Directory>
</VirtualHost>

jdMorgan

5:16 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



davistv,

Welcome to WebmasterWorld!

Most Apache configuration directives have no provisions for dereferencing variables.

Large hosts typically use a shell script to generate the configuration (httpd.conf) file, or 'extended' VPS configuration files such as conf.d, for new domains as they are added. Perhaps this approach would be workable for your needs.

Each Apache directive description starts with a list of the directive's syntax, execution context, core status, and module name. The syntax description should be your guide as to whether the directive can accept variables.

Jim

extras

10:17 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



VirtualDocumentRoot (mod_vhostalias) can do what you want (other than logging part).

For the logging, I guess you can use split-logfile,
[httpd.apache.org...]

Or use pipe for CustomLog.
[httpd.apache.org...]

If you search, you may find more solutions, like this.
[logtomysql.sourceforge.net...]
[serverwatch.com...]