X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=apache-site;h=2405713b8f6257a374ce3b2c6975a9bbf1f42671;hb=8d1ae39c659072b6407e913ac8a4df998f2c159a;hp=32c9f82cca78dbb3866218000d456bf145217e16;hpb=d8e7127346089f666eaff775cad4d2d0b40a6ec9;p=basic-https-conf diff --git a/apache-site b/apache-site index 32c9f82..2405713 100755 --- a/apache-site +++ b/apache-site @@ -1,4 +1,4 @@ -#!/bin/bash -l +#!/bin/bash # Copyright (C) 2016 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,50 +13,60 @@ # See the License for the specific language governing permissions and # limitations under the License. +[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" + set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR usage() { cat < +echo "$0: creating $vhost_file" +cat >$vhost_file < ServerName $h ServerAlias www.$h DocumentRoot $root EOF if [[ $extra_settings ]]; then - cat $extra_settings | sudo tee -a /etc/apache2/sites-enabled/$h.conf + cat -- $extra_settings >>$vhost_file +fi + +# go faster! +if [[ -e /etc/apache2/mods-available/http2.load ]]; then + # https://httpd.apache.org/docs/2.4/mod/mod_http2.html + a2enmod http2 + cat >>$vhost_file <>$vhost_file <>$vhost_file <$redir_file <<'EOF' +# vhost_combined with %D (request time in microseconds) +# this file is just a convenient place to drop it. +LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D" vhost_time_combined ServerAdmin webmaster@localhost DocumentRoot /var/www/html - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined + CustomLog ${APACHE_LOG_DIR}/httpsredir-access.log combined RewriteEngine on # ian: removed so it's for all sites @@ -118,9 +190,18 @@ RewriteEngine on RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] EOF + if ! $listen_80; then + cat >>$redir_file <<'EOF' +Listen 80 +EOF + fi + fi - sudo mkdir -p /etc/letsencrypt - sudo dd of=/etc/letsencrypt/options-ssl-apache.conf <<'EOF' + mkdir -p /etc/letsencrypt + + # this is from cerbot, see below. + echo "$0: creating $certbot_ssl_conf" + cat >$certbot_ssl_conf <<'EOF' # Baseline setting to Include for SSL sites SSLEngine on @@ -145,14 +226,39 @@ LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common #Header edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4" EOF + upstream=https://github.com/certbot/certbot/raw/master/certbot-apache/certbot_apache/options-ssl-apache.conf + if ! diff -c <(wget -q -O - $upstream) $certbot_ssl_conf; then + cat <>$vhost_file < +EOF -# vim: syntax=apache ts=4 sw=4 sts=4 sr noet +if ! $listen_port; then + # reference: https://httpd.apache.org/docs/2.4/mod/mpm_common.html#listen + cat >>$vhost_file <