Skip to content

Instantly share code, notes, and snippets.

@AwokeKnowing
Last active September 21, 2018 21:25
Show Gist options
  • Save AwokeKnowing/e2aba8ea9e90ae16af804c61be2705b0 to your computer and use it in GitHub Desktop.
Save AwokeKnowing/e2aba8ea9e90ae16af804c61be2705b0 to your computer and use it in GitHub Desktop.
Docker set up a front end website with ssl on blank server (with port 443 open)

Easily set up a front end website with ssl on blank server (with port 443 open)

before you start, you need

  1. install docker

  2. get my.pub.lic.ip (curl https://wtfismyip.com/text)

  3. place the certificate files

/etc/ssl/certs/__mydomain_com.crt
/etc/ssl/certs/__mydomain_com.ca-bundle
/etc/ssl/certs/myprivate.key
  1. download your site and enter it's root directory (eg install git, git clone site mysite, cd mysite)

  2. substitute the ip (my.pub.lic.ip) and certificate filenames (mydomain, myprivate.key) below and run:

docker run --name mysite -d \
  --restart unless-stopped \
  -p my.pub.lic.ip:80:80 \
  -p my.pub.lic.ip:443:443 \
  -v /etc/ssl/certs/__mydomain_com.crt:/etc/ssl/certs/__mydomain_com.crt:ro  \
  -v /etc/ssl/certs/__mydomain_com.ca-bundle:/etc/ssl/certs/__mydomain_com.ca-bundle:ro  \
  -v /etc/ssl/certs/myprivate.key:/etc/ssl/certs/myprivate.key:ro  \
  -v $(pwd):/var/www/html \
  php:7.2-apache

docker exec mysite sh -c "printf '%s\n' \
'<IfModule mod_ssl.c>' \
'    <VirtualHost _default_:443>' \
'        ServerAdmin webmaster@localhost' \
'        DocumentRoot /var/www/html' \
'        #LogLevel info ssl:warn' \
'        ErrorLog ${APACHE_LOG_DIR}/error.log' \
'        CustomLog ${APACHE_LOG_DIR}/access.log combined' \
'        SSLEngine on' \
'        SSLCertificateFile /etc/ssl/certs/__mydomain_com.crt ' \
'        SSLCertificateKeyFile /etc/ssl/certs/myprivate.key' \
'        SSLCertificateChainFile /etc/ssl/certs/__mydomain_com.ca-bundle' \
'    </VirtualHost>' \
'</IfModule>'  \
> /etc/apache2/sites-enabled/default-ssl.conf"

docker exec mysite sh -c "a2enmod ssl && /etc/init.d/apache2 restart"

Now you should be able to goto https://[yoursite].com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment