X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=apache-site;h=aaefd9ee7beafc5fc7815597b647f36560a8bb1d;hb=b1314beccfa3fb9f70e82edd153395de00939dfd;hp=32c9f82cca78dbb3866218000d456bf145217e16;hpb=d8e7127346089f666eaff775cad4d2d0b40a6ec9;p=basic-https-conf diff --git a/apache-site b/apache-site index 32c9f82..aaefd9e 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,6 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# run as root. +[[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" + set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR @@ -25,10 +28,11 @@ location for storing certs. EXTRA_SETTINGS_FILE can be - for stdin -p PORT --i Insecure, no ssl --h|--help Print help and exit --r DocumentRoot --- Subsequent arguments are never treated as options +-i Insecure, no ssl +-c CERT_DIR Default is /p/c/machine_specific/\$HOSTNAME/webservercerts +-h|--help Print help and exit +-r DocumentRoot +-- Subsequent arguments are never treated as options Note: options and non-options can be in any order. EOF @@ -37,6 +41,7 @@ EOF ##### begin command line parsing ######## +cert_dir=/p/c/machine_specific/$HOSTNAME/webservercerts ssl=true extra_settings= args=() @@ -44,6 +49,7 @@ port="*:443" while [[ $1 ]]; do case $1 in -i) ssl=false; shift ;; # i for insecure + -c) cert_dir="$2"; shift 2 ;; -p) port="$2"; shift 2 ;; -r) root="$2"; shift 2 ;; --) shift; break ;; @@ -68,8 +74,8 @@ if [[ ! $root ]]; then root=/var/www/$h/html fi + ##### end command line parsing ######## -cdir=/p/c/machine_specific/$HOSTNAME/webservercerts # taken from the let's encrypt generated site, using # ./certbot-auto --apache (should use the test mode to check if there are updates) @@ -83,9 +89,10 @@ cdir=/p/c/machine_specific/$HOSTNAME/webservercerts # https://mozilla.github.io/server-side-tls/ssl-config-generator/ -sudo rm -f /etc/apache2/sites-enabled/000-default.conf +rm -f /etc/apache2/sites-enabled/000-default.conf -sudo dd of=/etc/apache2/sites-enabled/$h.conf < ServerName $h ServerAlias www.$h @@ -93,24 +100,32 @@ sudo dd of=/etc/apache2/sites-enabled/$h.conf < 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 @@ -119,8 +134,11 @@ RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] EOF - sudo mkdir -p /etc/letsencrypt - sudo dd of=/etc/letsencrypt/options-ssl-apache.conf <<'EOF' + mkdir -p /etc/letsencrypt + + base_file=/etc/letsencrypt/options-ssl-apache.conf + # this is from cerbot, see below. + dd of=$base_file <<'EOF' # Baseline setting to Include for SSL sites SSLEngine on @@ -145,14 +163,33 @@ 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) $base_file; then + cat < # vim: syntax=apache ts=4 sw=4 sts=4 sr noet EOF -s a2enmod ssl rewrite # rewrite needed for httpredir -ser restart apache2 +a2enmod ssl rewrite # rewrite needed for httpredir +service apache2 restart + +# I rarely look at how much traffic I get, so let's keep that info +# around for longer than the default of 2 weeks. +sed -ri --follow-symlinks 's/^(\s*rotate\s).*/\1 365/' /etc/logrotate.d/apache2