Skip to content

Instantly share code, notes, and snippets.

@sourcec0de
Forked from andrewn/instructions.md
Created April 10, 2018 06:35
Show Gist options
  • Save sourcec0de/ac2ea9b1d90ca64057916bbe39a948f6 to your computer and use it in GitHub Desktop.
Save sourcec0de/ac2ea9b1d90ca64057916bbe39a948f6 to your computer and use it in GitHub Desktop.
Testing SSL (LetsEncrypt certificate and loopback domain)

This relies on having a public domain name whose DNS records you can control. We'll create a DNS entry that will loopback to localhost when requested.

For example: localhost.example.com will tell the browser to load the IP 127.0.0.1

You must have control of the DNS records of example.com for this to work.

  1. Create the loopback A record for localhost.example.com:

    In your DNS provider's control panel:

      Type: A
      Name: localhost.example.com.
      Data: 127.0.0.1
      TTL: 3600
  1. After a while, the following command:
    $ dig a localhost.example.com.

    ;; ANSWER SECTION:
    localhost.example.com.	3599 IN	A	127.0.0.1
  1. Install LetsEncrypt's certbot so we can generate a valid SSL cert:
    brew install certbot
  1. Generate a SSL cert for your domain using the DNS challenge type which means you won't need to have a server running on this domain:
    sudo certbot certonly --config-dir . --work-dir . --logs-dir . --manual --preferred-challenges dns
  1. Enter the domain name when prompted:
    localhost.example.com
  1. Ok with logging? Yes

  2. Add the DNS record and TXT value in your DNS provider's control panel as requested by certbot. Do not press Enter until it's been deployed.

  3. There are a few more questions then certbot will have generated files in the directory you ran the command in:

    live
    └── localhost.example.com
        ├── README
        ├── cert.pem
        ├── chain.pem
        ├── fullchain.pem
        └── privkey.pem
  1. Use the redbox proxy to point to the generated certificates and start on port 443:
    sudo node redbird-proxy.js live/localhost.example.com/
  1. Set the API_URL in .env to:
    API_URL=https://localhost.example.com/api
  1. Start HTTP client on port 80 (edit .env to set PORT=80)
    sudo npm start
  1. Visit https://localhost.example.com

The HTTPS server should be available without any browser warnings. HTTP version will be available on http://localhost.example.com.

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