2 # Copyright (C) 2016 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21 Usage: ${0##*/} [EXTRA_SETTINGS_FILE] DOMAIN
22 Setup apache virtualhost config with https using
23 ssl config provided by let's encrypt and my standard
24 location for storing certs.
26 EXTRA_SETTINGS_FILE can be - for stdin
29 -h|--help Print help and exit
31 -- Subsequent arguments are never treated as options
33 Note: options and non-options can be in any order.
38 ##### begin command line parsing ########
46 -i) ssl
=false
; shift ;; # i for insecure
47 -p) port
="$2"; shift 2 ;;
48 -r) root
="$2"; shift 2 ;;
50 -?
*|
-h|
--help) usage
;;
51 *) args
+=("$1"); shift ;;
56 if (( ${#args[@]} == 2 )); then
57 read extra_settings h
<<<"${args[@]}"
59 read h
<<<"${args[@]}"
63 echo "$0: error: expected domain arg"
67 if [[ ! $root ]]; then
71 ##### end command line parsing ########
72 cdir
=/p
/c
/machine_specific
/$HOSTNAME/webservercerts
74 # taken from the let's encrypt generated site, using
75 # ./certbot-auto --apache (should use the test mode to check if there are updates)
78 # I could have also used the mozilla generator this, but it had some open issues
80 # so I figured I would check out let's encrypt.
81 # It's a little more liberal, but still get's an A in ssl labs,
82 # so, meh, I'll use it.
83 # https://mozilla.github.io/server-side-tls/ssl-config-generator/
86 sudo
rm -f /etc
/apache
2/sites-enabled
/000-default.conf
88 sudo
dd of
=/etc
/apache
2/sites-enabled
/$h.conf
<<EOF
95 if [[ $extra_settings ]]; then
96 cat $extra_settings | sudo
tee -a /etc
/apache
2/sites-enabled
/$h.conf
100 sudo
tee -a /etc
/apache
2/sites-enabled
/$h.conf
<<EOF
101 SSLCertificateFile $cdir/$h-chained.pem
102 SSLCertificateKeyFile $cdir/$h-domain.key
103 Include /etc/letsencrypt/options-ssl-apache.conf
106 sudo
dd of
=/etc
/apache
2/sites-enabled
/httpsredir.conf
<<'EOF'
108 ServerAdmin webmaster@localhost
109 DocumentRoot /var/www/html
112 ErrorLog ${APACHE_LOG_DIR}/error.log
113 CustomLog ${APACHE_LOG_DIR}/access.log combined
116 # ian: removed so it's for all sites
117 #RewriteCond %{SERVER_NAME} =certbot.iank.bid
118 RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
122 sudo mkdir
-p /etc
/letsencrypt
123 sudo
dd of
=/etc
/letsencrypt
/options-ssl-apache.conf
<<'EOF'
124 # Baseline setting to Include for SSL sites
128 # Intermediate configuration, tweak to your needs
129 SSLProtocol all -SSLv2 -SSLv3
130 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
131 SSLHonorCipherOrder on
134 SSLOptions +StrictRequire
136 # Add vhost name to log entries:
137 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
138 LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
140 #CustomLog /var/log/apache2/access.log vhost_combined
142 #ErrorLog /var/log/apache2/error.log
144 # Always ensure Cookies have "Secure" set (JAH 2012/1)
145 #Header edit Set-Cookie (?i)^(.*)(;\s*secure)??((\s*;)?(.*)) "$1; Secure$3$4"
149 sudo
tee -a /etc
/apache
2/sites-enabled
/$h.conf
<<EOF
150 ErrorLog \${APACHE_LOG_DIR}/error.log
151 CustomLog \${APACHE_LOG_DIR}/access.log combined
154 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
157 s a2enmod ssl rewrite
# rewrite needed for httpredir