EXTRA_SETTINGS_FILE can be - for stdin
+-a IPv4_ADDR IP address to listen on. Default all addresses.
+ ipv6 address support could be added to this script.
-e EMAIL Contact address for let's encrypt. Default is
root@\$(hostname --fqdn')
which is root@$(hostname --fqdn) on this host.
ssl=true
extra_settings=
port=443
-temp=$(getopt -l help e:if:p:r:sh "$@") || usage 1
+temp=$(getopt -l help a:e:if:p:r:sh "$@") || usage 1
+vhostip='*'
eval set -- "$temp"
while true; do
case $1 in
+ -a)
+ listenip="$2:"
+ vhostip="$2"
+ shift 2 ;;
-e) email="$2"; shift 2 ;;
-f) proxy="$2"; shift 2 ;;
-i) ssl=false; shift ;;
cert_dir=/etc/letsencrypt/live/$h
mkdir -p $root
-vhost_file=$se/$h.conf
+case $port in
+ 80|443)
+ vhost_file=$se/$h.conf
+ ;;
+ *)
+ vhost_file=$se/$h-$port.conf
+ ;;
+esac
redir_file=$se/$h-redir.conf
if [[ $port == 80 ]]; then
# --hsts --staple-ocsp --uir --must-staple
certbot certonly -n --email $email --no-self-upgrade \
--agree-tos --${t%2} -d $h
- rm $vhost_file
+ # cleanup the call to ourselves a short bit ago
+ rm $se/$h.conf
fi
-
-
fi
done
done
-
+ echo "$0: creating $vhost_file"
cat >$vhost_file <<EOF
-<VirtualHost *:$port>
+<VirtualHost $vhostip:$port>
ServerName $h
ServerAlias www.$h
DocumentRoot $root
Header always set Content-Security-Policy upgrade-insecure-requests
EOF
- echo "$0: creating $redir_file"
- cat >$redir_file <<EOF
+ if (( port == 443 )); then
+ echo "$0: creating $redir_file"
+ cat >$redir_file <<EOF
<VirtualHost *:80>
ServerName $h
ServerAdmin webmaster@localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
EOF
- if ! $listen_80; then
- cat >>$redir_file <<'EOF'
+ if ! $listen_80; then
+ cat >>$redir_file <<'EOF'
Listen 80
EOF
+ fi
fi
# this is a copy of a file certbot, see below.
if ! $listen_port; then
# reference: https://httpd.apache.org/docs/2.4/mod/mpm_common.html#listen
cat >>$vhost_file <<EOF
-listen ${port}${https_arg}
+listen ${listenip}${port}${https_arg}
EOF
fi
server {
server_name $h www.$h;
root $root;
- listen $port $ssl_arg;
+ listen $listenip$port $ssl_arg;
+EOF
+ if [[ ! $listenip ]]; then
+ cat >>$vhost_file <<EOF
listen [::]:$port $ssl_arg;
+EOF
+ fi
+ cat >>$vhost_file <<EOF
location $root {
autoindex off;
}
include $common_ssl_conf;
EOF
- cat >$redir_file <<EOF
+ if (( port == 443 )); then
+ cat >$redir_file <<EOF
server {
server_name $h www.$h;
listen 80 $http2_arg;
return 301 https://$server_name$request_uri;
}
EOF
+ fi
fi # end if $ssl
if [[ $extra_settings ]]; then