Lets say I have this folder structure on disk:
/var/www/site1.domain.com
/var/www/site2.domain.com
/var/www/site3.domain.com
/var/www/site4.domain.com
/var/www/site5.anotherdomain.com
/var/www/site6.anotherdomain.com
/var/www/site7.anotherdomain.com
/var/www/site8.anotherdomain.com
These are all similar plain html/css/js websites configured in exactly the same way.
Is it possible to set up apache in such a way that incoming requests for each domain are directed to the appropriate directory without configuring hundreds of <VirtualHost..>
nodes? I guess I could auto generate them, but I’m hoping for a fancy go look in the request’s domain’s folder kind of configuration..
Is this possible? Even if it is possible, are there any concerns with this security or otherwise?
If it is not possible, is there another web technology like nginx for example that can do this?
3
Answers
So it turns out there is an apache module for this:
Read more about the module here:
http://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html
Here is the config that worked for me:
It’s super easy with nginx:
Plus nginx is blazingly fast. If you wish to stick to Apache though, you ought to read this: https://httpd.apache.org/docs/2.4/vhosts/mass.html
Yes there are security and other concerns. Is better to have one virtualhost per site with separate logging and separate SSL certificates etc.
If they are different sites is better to have they separated because:
/var/www/site1.domain.com-backup
or/var/www/secret-logs
they can be accessed.Is better to auto-generate them. You can use many templating tools from a simple bash script which accepts some parameters on envvars to more complex tools like SaltStack / Ansible.
Here a simple bash script to do it, it should be adapted to your needs:
To execute the script name it
nginx-site-generator
, give execution permissions and: