Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Virtual host file for port 80 that redirects 'www' alias to main domain, uses 'cronolog' to rotate error and access logs, redirects non-whitelisted hosts to main site, allows access to itself via URL-based cron jobs, and prompts users of permitted group for username and password via basic authentication. Also includes rewrite map to redirect dom…
<VirtualHost *:80>
ServerName domain.com
RewriteEngine On
RewriteMap redirect_map_master txt:vhosts.d/includes/redirect_map_master
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteCond ${redirect_map_master:%2|domain.com} ^(.+)$ [NC]
RewriteRule ^/$ http://%1 [L,R=301]
</VirtualHost>
<VirtualHost *:80>
ServerName sub.domain.com
ServerAlias www.sub.domain.com
DocumentRoot /var/www/domains/domain.com/sub/htdocs
ErrorLog "|/usr/local/sbin/cronolog -l /var/www/domains/domain.com/sub/logs/error_log /var/www/domains/domain.com/sub/logs/%Y/%m/%Y-%m-%d-error_log"
CustomLog "|/usr/local/sbin/cronolog -l /var/www/domains/domain.com/sub/logs/access_log /var/www/domains/domain.com/sub/logs/%Y/%m/%Y-%m-%d-access_log" combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.sub.domain.com [NC]
RewriteRule ^/(.*)$ http://sub.domain.com/$1 [R=301,L]
RewriteCond %{REMOTE_HOST} !^111\.111\.111\.111
RewriteCond %{REMOTE_HOST} !^222\.222\.222
RewriteRule / http://domain.com [R=302,L]
<Directory />
AuthType Basic
AuthName "Restricted Area"
AuthBasicProvider file
AuthUserFile /var/www/htpasswd/users
AuthGroupFile /var/www/htpasswd/groups
Require group groupname1
Order Allow,Deny
Allow from 111.111.111.111
Satisfy any
</Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment