usage () { echo "You must set a $1 !" echo "Usage:" echo " create_apache_conf.sh " exit 0 } if [ -z $1 ]; then usage "USER" fi USER=$1 cat > /etc/apache2/sites-available/$USER.kresus.neodarz.net.conf << EOF ServerName $USER.kresus.neodarz.net ServerAdmin me@example.net #Alias /.well-known/acme-challenge /tmp/.well-known/acme-challenge Options None AllowOverride None Require all granted AddDefaultCharset off AuthType None Satisfy any Redirect permanent / https://$USER.kresus.neodarz.net/ ErrorLog /home/website/kresus-gen/logs/error.log CustomLog /home/website/kresus-gen/logs/access.log combined EOF cat > /etc/apache2/sites-available/$USER.kresus.neodarz.net-le-ssl.conf << EOF ServerName $USER.kresus.neodarz.net ServerAdmin me@example.net ProxyPass "/" "http://127.0.0.1:9876/" ProxyPassReverse "/" "http://127.0.0.1:9876/" Alias /.well-known/acme-challenge /tmp/.well-known/acme-challenge Options None AllowOverride None Require all granted AddDefaultCharset off AuthType None Satisfy any AuthUserFile /home/website/kresus-gen/$USER.kresus.neodarz.net/.htpasswd AuthName "Authentification" AuthType Basic Require valid-user SSLEngine on SSLCertificateKeyFile /etc/letsencrypt/live/$USER.kresus.neodarz.net/privkey.pem SSLCertificateFile /etc/letsencrypt/live/$USER.kresus.neodarz.net/fullchain.pem Header always set Strict-Transport-Security "max-age=15768000" SSLOptions +StdEnvVars SSLOptions +StdEnvVars ErrorLog /home/website/kresus-gen/logs/error.log CustomLog /home/website/kresus-gen/logs/access.log combined # vim: syntax=apache ts=4 sw=4 sts=4 sr noet EOF certbot --apache -d $USER.kresus.neodarz.net a2ensite $USER.kresus.neodarz.net systemctl reload apache2