Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have to define about 100 subdomain virtualhost entries in server config file . I want to know if there is any way to do it with regular expression to increase codes in apache config file?

share|improve this question

2 Answers 2

You should have a look at this how to from the Apache documentation, I think that's what you need here:
http://httpd.apache.org/docs/2.2/vhosts/mass.html

The basic idea is to replace all of the static configuration with a mechanism that works it out dynamically. This has a number of advantages:

  • Your configuration file is smaller so Apache starts faster and uses less memory.

  • Adding virtual hosts is simply a matter of creating the appropriate directories in the filesystem and entries in the DNS - you don't need to reconfigure or restart Apache.

update:

Using Mass Virtual Hosting forbids the use of different log files:

The main disadvantage is that you cannot have a different log file for each virtual host; however if you have very many virtual hosts then doing this is dubious anyway because it eats file descriptors. It is better to log to a pipe or a fifo and arrange for the process at the other end to distribute the logs to the customers (it can also accumulate statistics, etc.).

However this is not really a problem because you can use the %v filter for CustomLog which places the ServerName in front of each logged request, you can then filter and split logs if necessary based on this.

A good practice is to put those logs in a mysql database (on the fly or through a cronjob, pipe or a fifo file) because SQL is a great tool to extract meaningful informations from them.
Have a look on this article which describes settign up (direct) database logging through mod_log_mysql:
http://onlamp.com/pub/a/apache/2005/02/10/database_logs.html

Storing your logs directly in a database mysql can be a good solution through the ARCHIVE storage engine but it has its own limitations (lock table on write). An alternative would be building you system on a more standard storage engine (innodb, xtradb for example), if you already have a mysql server I'd try that before other solutions as it doesn't require much learning.

If you feel a little more adventurous you can have a look at MongoDB, as a document oriented database it is particularly fit as a log storage system (fast, powerful filter capabilities, speed of insertion/read) but be sure to have a good dedicated server for it as you'll need RAM for it to behave adequately.

You'll find details on MongoDB logging here:

share|improve this answer
    
But it is said in the documentation that it doesn't support different log file for each virtualhost . but i need this feature . –  hd01 Dec 6 '11 at 8:51
    
Then I can say you've got a problem :) Anyway you can always put those logs in a database, sorting them by vhost using the "%v" filter for you CustomLogs. You can even transfer those logs with a script if you don't want apache logging directly to your mysql database. I'll add some links about that in my answer above. –  Shadok Dec 6 '11 at 10:03
    
Since apache allows you to send logs anywhere you want (using a pipe), this is not a real problem. Simply pipe the log into a processor that splits up the vhosts to different files; if you prepend the logs with %v, or even {HTTP_HOST}i, this is easy to do with awk(1). However, much will depend on volume - if this is a million-hits-per-day host, a mysql database may fulfill your needs, at considerable performance cost, but if it hits 1 million per hour, storing logs in a database is counter-productive. –  adaptr Dec 6 '11 at 10:57

No, but what are you trying to do? Having a regex in the <VirtualHost> line would make no sense.

ServerAlias can have wildcards, not regex; this might give you what you need?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.