aboutsummaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-13 18:01:42 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-13 18:01:42 +0200
commit344f64853a083222c0205905dab4ecd41d6570d9 (patch)
tree1fc70bc1a7fdbbcddc7ed7d09eefd11ff6e9c3ec /usr
parent7c13a4f0641e6d515da9c87bbb684272236d4251 (diff)
downloadrbsd-344f64853a083222c0205905dab4ecd41d6570d9.tar.gz
httpd.conf: Add virtual host configuration
Diffstat (limited to 'usr')
-rw-r--r--usr/pkg/etc/httpd/httpd.conf123
1 files changed, 121 insertions, 2 deletions
diff --git a/usr/pkg/etc/httpd/httpd.conf b/usr/pkg/etc/httpd/httpd.conf
index 0d85006..f5166f0 100644
--- a/usr/pkg/etc/httpd/httpd.conf
+++ b/usr/pkg/etc/httpd/httpd.conf
@@ -108,7 +108,7 @@ LoadModule dir_module lib/httpd/mod_dir.so
#LoadModule speling_module lib/httpd/mod_speling.so
#LoadModule userdir_module lib/httpd/mod_userdir.so
LoadModule alias_module lib/httpd/mod_alias.so
-#LoadModule rewrite_module lib/httpd/mod_rewrite.so
+LoadModule rewrite_module lib/httpd/mod_rewrite.so
LoadModule perl_module lib/httpd/mod_perl.so
<IfModule unixd_module>
@@ -136,7 +136,7 @@ DocumentRoot "/var/www/rbsd/htdocs"
</Directory>
<IfModule dir_module>
- DirectoryIndex index.html
+ DirectoryIndex index.php index.html
</IfModule>
<Files ".ht*">
@@ -235,3 +235,122 @@ SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
+<Perl>
+use warnings;
+use subs qw/vhost idn with_idn block/;
+use Tie::DxHash;
+
+# Long-term redirections
+
+my %redir = (
+ 'git.ankarstrom.se' => block(
+ RewriteRule => '^Apache-Inject\.git/?$ /cpan/Apache-Inject/ [L,R,END]',
+ RewriteRule => '^([^/]*)\.git(/.*)?$ /$1$2 [L,R,END]',
+ ),
+ 'john.ankarstrom.se' => block(
+ Redirect => '301 /feed.rss /articles.xml',
+ Redirect => '301 /feed.php /articles.xml',
+ Redirect => '301 /english/texts/replacing-javascript /replacing-javascript',
+ Redirect => '301 /web/separation-of-concerns.html /separation-of-concerns',
+ Redirect => '301 /unix/learning-c.html /learning-c',
+ Redirect => '301 /scripts http://git.ankarstrom.se/',
+ Redirect => '301 /software http://git.ankarstrom.se',
+ Redirect => '301 /ansi-sv-layout /sv-ansi',
+ ),
+ 'software.ankarstrom.se' => block(
+ RewriteRule => '^(win32/)?ahk(/.*)? http://git.ankarstrom.se/ahk/about/ [L,R]',
+ RewriteRule => '^(win32/)?drm(/.*)? http://git.ankarstrom.se/drm/about/ [L,R]',
+ RewriteRule => '^(win32/)?run(/.*)? http://git.ankarstrom.se/run/about/ [L,R]',
+ RewriteRule => '^(win32/)?tt(/.*)? http://git.ankarstrom.se/tt/about/ [L,R]',
+ RewriteRule => '^(win32/)?watch(/.*)? http://git.ankarstrom.se/watch/about/ [L,R]',
+ RewriteRule => '^.* http://git.ankarstrom.se/ [L,R]',
+ ),
+);
+
+# Virtual host configuration
+
+vhost block(ServerName => 'ankarstrom.se',
+ ServerAlias => [with_idn 'www.ankarstrom.se'],
+ DocumentRoot => '/var/www/rbsd/htdocs',
+);
+
+vhost block(ServerName => 'lamnafacebook.nu',
+ DocumentRoot => '/var/www/facebook/htdocs',
+ ServerAlias => [with_idn 'www.lamnafacebook.nu'],
+);
+
+vhost block(ServerName => 'git.ankarstrom.se',
+ Directory => block('/var/www/git/htdocs' => block(
+ DirectoryIndex => 'cgit.cgi',
+ Options => '+ExecCGI',
+ RewriteEngine => 'On',
+ RewriteCond => '%{REQUEST_FILENAME} !-f',
+ RewriteCond => '%{REQUEST_FILENAME} !-d',
+ RewriteRule => '(.*) cgit.cgi/$1 [END,QSA]',
+ )),
+);
+
+vhost block(ServerName => 'dev.ankarstrom.se');
+vhost block(ServerName => 'img.ankarstrom.se');
+vhost block(ServerName => 'john.ankarstrom.se');
+vhost block(ServerName => 'mail.ankarstrom.se');
+vhost block(ServerName => 'software.ankarstrom.se');
+
+# Default virtual host configuration
+
+sub vhost {
+ my $vhost = $_[0]; # this should be a hash ref tied to Tie::DxHash
+
+ if (!$vhost->{ServerName}) {
+ warn 'Call to vhost missing ServerName, skipping virtual host';
+ return;
+ }
+
+ # Merge directives of which only one instance is allowed
+ if (!$vhost->{DocumentRoot}) {
+ (my $subdomain = $vhost->{ServerName}) =~ s/\..*//;
+ $vhost->{DocumentRoot} = "/var/www/$subdomain/htdocs";
+ }
+
+ # Merge directives of which multiple instances are allowed
+ my $default = block(
+ ServerAlias => idn($vhost->{ServerName}),
+ Directory => block(
+ $vhost->{DocumentRoot} => block(
+ Options => 'Indexes FollowSymLinks',
+ AllowOverride => 'All',
+ Require => 'all granted',
+ exists $redir{$vhost->{ServerName}} ? (RewriteEngine => 'On') : (),
+ %{$redir{$vhost->{ServerName}}},
+ ),
+ ),
+ );
+
+ my @keys = keys %$vhost;
+ my @values = values %$vhost;
+ for (my $i = 0; $i < @keys; $i++) {
+ $default->{$keys[$i]} = $values[$i];
+ }
+ $vhost = $default;
+
+ $VirtualHost{'*:80'} = [@{$VirtualHost{'*:80'}||[]}, $vhost];
+}
+
+sub idn {
+ my ($domain) = @_;
+ $domain =~ s/ankarstrom\.se$/xn--ankarstrm-77a.se/;
+ $domain =~ s/lamnafacebook\.nu$/xn--lmnafacebook-gcb.nu/;
+ return $domain;
+}
+
+sub with_idn {
+ return $_[0], idn $_[0];
+}
+
+sub block {
+ my %hash;
+ tie %hash, 'Tie::DxHash';
+ %hash = @_;
+ return \%hash;
+}
+</Perl>