X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=apache-site;h=5e3f8c463d07d6c267e9d72a7b6e7754721a98be;hb=3139f7f6b990e8ca3aa491078e3496dc97dc4c36;hp=d99bf9698c48169bd8ccefb58df238a7104719db;hpb=bcdbffa4898135bc42772e1b9b706dc2acadfbdd;p=basic-https-conf diff --git a/apache-site b/apache-site index d99bf96..5e3f8c4 100755 --- a/apache-site +++ b/apache-site @@ -13,53 +13,58 @@ # 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 < +tee $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 | tee -a $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 + tee -a $vhost_file <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 @@ -122,9 +175,17 @@ RewriteEngine on RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] EOF + if ! $listen_80; then + tee -a $redir_file <<'EOF' +Listen 80 +EOF + fi + fi + + mkdir -p /etc/letsencrypt - sudo mkdir -p /etc/letsencrypt - sudo dd of=/etc/letsencrypt/options-ssl-apache.conf <<'EOF' + # this is from cerbot, see below. + cat >$certbot_ssl_conf <<'EOF' # Baseline setting to Include for SSL sites SSLEngine on @@ -149,14 +210,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 < +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 + tee -a $vhost_file <