Automatically generate virtual-hosts in Apache
I have a lot of virtual-hosts on my development-machine.
Since I find it quite tedious to change the apache-config for every new vhost and restart apache after that, I wrote the following apache-config that redirects any host <name>.home
to a folder home/Server/sites/<name>
automatically
https_vhosts.conf
apache_conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName home
DocumentRoot "/Users/abraham/Server/home"
ServerAdmin webmaster@aprz.de
LogLevel debug
LogFormat "%A %h %l %u %t \"%r\" %s %b" vcommon
ErrorLog /Users/abraham/Server/error.log
CustomLog /Users/abraham/Server/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.home
VirtualDocumentRoot "/Users/abraham/Server/sites/%-2+"
UseCanonicalName Off
ServerAdmin webmaster@aprz.de
LogLevel debug
LogFormat "%A %h %l %u %t \"%r\" %s %b" vcommon
ErrorLog /Users/abraham/Server/error.log
CustomLog /Users/abraham/Server/access.log combined
<filesMatch "\.(html|htm|js|css|apk)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</filesMatch>
</VirtualHost>
<Directory "/Users/abraham/Server/sites">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This file works flawlessly with the integrated Apache of MAMP. (Without MAMP Pro)
If I now want to create a new virtual host, I just create a new folder under home/Server/sites
.
Post-Meta
- Published: July 21, 2019
- Last modified: July 21, 2019
- Tags: apache virtualhosts
Comments