From: Ian Kelling Date: Sun, 2 Apr 2017 01:06:01 +0000 (-0700) Subject: allow alternate ports for apache X-Git-Url: https://iankelling.org/git/?p=basic-https-conf;a=commitdiff_plain;h=3139f7f6b990e8ca3aa491078e3496dc97dc4c36 allow alternate ports for apache --- diff --git a/apache-site b/apache-site index 9a22d2a..5e3f8c4 100755 --- a/apache-site +++ b/apache-site @@ -20,7 +20,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR usage() { cat <$vhost_file < +redir_file=/etc/apache2/sites-enabled/httpsredir.conf + +# note, we exepct ServerRoot of /etc/apache2 +cd /etc/apache2 +conf_files=(apache2.conf) + +# apache requires exactly 1 listen directive per port (when no ip is also given), +# so we have to parse the config to do it programatically. +listen_80=false +listen_port=false +while (( i=0; i < ${#conf_files[@]}; i++ )); do + f="${conf_files[i]}" + # note: globs are expanded here: + conf_files+=( $(sed -rn "s,^\s*Include(Optional)?\s+(\S+).*,\2,p" "$f") ) + case $(readlink -f "$f") in + $vhost_file|$redir_file) continue ;; + esac + for p in $(sed -rn "s,^\s*Listen\s+(\S+).*,\1,p" "$f"); do + case $p in + 80) listen_80=true ;; + $port) listen_port=true ;; + esac + done +done + +if $ssl; then + https_arg=" https" +fi + + +tee $vhost_file < ServerName $h ServerAlias www.$h DocumentRoot $root @@ -110,7 +142,7 @@ fi 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 @@ -140,11 +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 # this is from cerbot, see below. - cat >$certbot_ssl_conf <<'EOF' + cat >$certbot_ssl_conf <<'EOF' # Baseline setting to Include for SSL sites SSLEngine on @@ -189,9 +230,15 @@ tee -a $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 + tee -a $vhost_file <&2' ERR usage() { cat <