From 0fcf341478df2184e3e78a29d093aa6017911251 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Sat, 4 Aug 2018 16:20:04 +0100 Subject: [PATCH] Teach trac cookbook about site aliases --- cookbooks/trac/recipes/default.rb | 4 +- cookbooks/trac/templates/default/apache.erb | 76 +++++++++++++-------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/cookbooks/trac/recipes/default.rb b/cookbooks/trac/recipes/default.rb index 0d08e322b..4f5526002 100644 --- a/cookbooks/trac/recipes/default.rb +++ b/cookbooks/trac/recipes/default.rb @@ -74,14 +74,14 @@ end apache_module "wsgi" ssl_certificate "trac.openstreetmap.org" do - domains "trac.openstreetmap.org" + domains ["trac.openstreetmap.org", "trac.osm.org"] notifies :reload, "service[apache2]" end apache_site site_name do template "apache.erb" directory site_directory - variables :user => "trac", :group => "trac" + variables :user => "trac", :group => "trac", :aliases => ["trac.osm.org"] end template "/etc/sudoers.d/trac" do diff --git a/cookbooks/trac/templates/default/apache.erb b/cookbooks/trac/templates/default/apache.erb index ad9429bb1..bc58ed276 100644 --- a/cookbooks/trac/templates/default/apache.erb +++ b/cookbooks/trac/templates/default/apache.erb @@ -3,48 +3,70 @@ WSGIDaemonProcess <%= @name %> user=<%= @user %> group=<%= @group %> maximum-requests=5000 threads=25 inactivity-timeout=180 - ServerName <%= @name %> - ServerAdmin webmaster@openstreetmap.org + ServerName <%= @name %> +<% @aliases.each do |alias_name| -%> + ServerAlias <%= alias_name %> +<% end -%> + ServerAdmin webmaster@openstreetmap.org - CustomLog /var/log/apache2/<%= @name %>-access.log combined - ErrorLog /var/log/apache2/<%= @name %>-error.log + CustomLog /var/log/apache2/<%= @name %>-access.log combined + ErrorLog /var/log/apache2/<%= @name %>-error.log - RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/ - RedirectPermanent / https://<%= @name %>/ + RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/ + RedirectPermanent / https://<%= @name %>/ +<% unless @aliases.empty? -%> - ServerName <%= @name %> - ServerAdmin webmaster@openstreetmap.org + ServerName <%= @aliases.first %> +<% @aliases.drop(1).each do |alias_name| -%> + ServerAlias <%= alias_name %> +<% end -%> + ServerAdmin webmaster@openstreetmap.org - SSLEngine on - SSLCertificateFile /etc/ssl/certs/<%= @name %>.pem - SSLCertificateKeyFile /etc/ssl/private/<%= @name %>.key + SSLEngine on + SSLCertificateFile /etc/ssl/certs/<%= @name %>.pem + SSLCertificateKeyFile /etc/ssl/private/<%= @name %>.key - CustomLog /var/log/apache2/<%= @name %>-access.log combined - ErrorLog /var/log/apache2/<%= @name %>-error.log + CustomLog /var/log/apache2/<%= @name %>-access.log combined + ErrorLog /var/log/apache2/<%= @name %>-error.log - DocumentRoot <%= @directory %>/htdocs - Alias /robots.txt <%= @directory %>/htdocs/site/robots.txt - WSGIScriptAlias / <%= @directory %>/cgi-bin/trac.wsgi + RedirectPermanent / https://<%= @name %>/ + +<% end -%> + + + ServerName <%= @name %> + ServerAdmin webmaster@openstreetmap.org + + SSLEngine on + SSLCertificateFile /etc/ssl/certs/<%= @name %>.pem + SSLCertificateKeyFile /etc/ssl/private/<%= @name %>.key + + CustomLog /var/log/apache2/<%= @name %>-access.log combined + ErrorLog /var/log/apache2/<%= @name %>-error.log + + DocumentRoot <%= @directory %>/htdocs + Alias /robots.txt <%= @directory %>/htdocs/site/robots.txt + WSGIScriptAlias / <%= @directory %>/cgi-bin/trac.wsgi - WSGIProcessGroup <%= @name %> + WSGIProcessGroup <%= @name %> - DefineExternalAuth osm pipe /usr/local/bin/trac-authenticate + DefineExternalAuth osm pipe /usr/local/bin/trac-authenticate - - AuthType Basic - AuthName "OpenStreetMap Trac" - AuthBasicProvider external - AuthExternal osm - Require valid-user - + + AuthType Basic + AuthName "OpenStreetMap Trac" + AuthBasicProvider external + AuthExternal osm + Require valid-user + /htdocs> - Require all granted + Require all granted /cgi-bin> - Require all granted + Require all granted -- 2.43.2