Skip to content

Commit 77a6587

Browse files
authored
Merge pull request dwyl#6 from dwyl/letsencrypt-ssl-tutorial
Tidy up Let's Encrypt SSL Tutorial
2 parents b309817 + 6462b7d commit 77a6587

File tree

3 files changed

+120
-54
lines changed

3 files changed

+120
-54
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ That will trigger the Heroku deployment of the Hello World Application!
148148
> In my case the URL for my app is: https://hello-world-heroku-node.herokuapp.com
149149
150150
You should expect to see: <br />
151-
![learn-heroku-result](https://cloud.githubusercontent.com/assets/194400/23249056/5490f418-f99a-11e6-9833-1e3b905d9c80.png)
151+
![learn-heroku-hello-world](https://cloud.githubusercontent.com/assets/194400/23319783/edd7954c-facf-11e6-9059-0862a69e1fd3.png)
152152

153-
#### Congratulations! You just _deployed_ your first app on Heroku!
153+
### Congratulations! You just _deployed_ your first app on Heroku!
154154

155155

156-
<br /><br /><br />
156+
<br /><br /><br /><br /><br /><br />
157157

158158
### Intermediate: Detailed Step-by-Step Instructions for _Your_ App
159159

160-
> To be added soon!
160+
> Coming soon!
161161
162162
### Intermediate: Environment Variables on Heroku
163163

@@ -168,7 +168,8 @@ see: [github.com/dwyl/learn-environment-variables#**environment-variables-on-her
168168

169169
A Version of your App for Each Pull Request!
170170

171-
> Help wanted!
171+
> First ensure that you _understand_ what Continuous Integration is...
172+
see: https://github.com/dwyl/learn-travis
172173

173174
### Advanced: Docker Containers
174175

SSL-certificate-step-by-step-setup-instructions.md

Lines changed: 113 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Step-by-Step Setup Instructions for Let's Encrypt
1+
![letsencrypt-760x320](https://cloud.githubusercontent.com/assets/194400/23311312/8c4cc85a-faad-11e6-912c-9cc96ec21da6.png)
22

3-
> Note: These instructions are only applicable to web apps
4-
with a custom domain name.
3+
# Step-by-Step Setup Instructions for Let's Encrypt _Free_ SSL
4+
5+
> _Note: These instructions are only applicable to web apps
6+
with a **custom domain** name_.
57

68

79
## Why?
@@ -12,13 +14,71 @@ to Secure/Encrypt all communications between users and your app.
1214

1315
## What?
1416

15-
Let's Encrypt offers a ***Free*** Automated SLL Certificate Service
16-
17+
Let's Encrypt offers a ***Free*** _Automated_ SSL Certificate Service
18+
brought to you by the **_non-profit_
19+
Internet Security Research Group** (ISRG).
1720
see: https://letsencrypt.org/about/
1821

22+
### Instructions Valid for Apps Written in _Any_ Language/Framework!
23+
24+
The instructions in this tutorial/guide are applicable
25+
to an app written in ***any language or framework***.
26+
You will _temporarily_ deploy a Node.js `http-server` to your Heroku app
27+
which will allow Let's Encrypt to _verify_ that you "_own_" the app/domain.
28+
29+
> _**Note**: No Node.js knowledge is assumed or required. You won't be
30+
writing a single line of JS code._
31+
32+
Once you have set up SSL you can deploy what ever kind of app you like.
33+
(_in our case the app is written in [Elixir/Phoenix!](https://github.com/dwyl/technology-stack/#the-pete-stack) ...
34+
node.js is just an easy way to get this working in a **generic** way._)
35+
1936
## How?
2037

21-
### Step 1: Install `certbot`
38+
"**certbot**" is the script that _automates_ the certificate creation process.
39+
40+
### Step 1: Clone this Repository to get the Setup Code
41+
42+
```
43+
git clone https://github.com/dwyl/learn-heroku.git
44+
cd learn-heroku
45+
```
46+
47+
### Step 2: Set Git Remote
48+
49+
Check what your _current_ `origin` remote is:
50+
```sh
51+
git remote -v
52+
```
53+
![git-remote](https://cloud.githubusercontent.com/assets/194400/23321003/400c1fa4-fad5-11e6-8e9b-0caf85963dd1.png)
54+
55+
Set it to what ever the git url is for the app you are setting up SSL for. e.g:
56+
```sh
57+
git remote set-url origin git@github.com:healthlocker/healthlocker.git
58+
```
59+
60+
Push your current branch to the GitHub repo:
61+
```sh
62+
git push --set-upstream origin letsencrypt-temporary-server
63+
```
64+
65+
### Step 3: _Temporarily_ Change the Branch Heroku Deploys from
66+
67+
![ssl1](https://cloud.githubusercontent.com/assets/194400/23256626/22f87da4-f9b8-11e6-96d1-72e50ebeffa4.png)
68+
69+
Change it to the name of your branch e.g:
70+
71+
![ssl2](https://cloud.githubusercontent.com/assets/194400/23256625/22f75cee-f9b8-11e6-896f-296e353429be.png)
72+
73+
It should look something like this:
74+
75+
![ssl-deploy-from-diff-branch-disable-ci-check](https://cloud.githubusercontent.com/assets/194400/23256955/7e62225c-f9b9-11e6-9ba0-74e5d2644f8a.png)
76+
remember to (_temporarily_) _dissable_ the checkbox `Wait for CI to
77+
pass before deploy` <br />
78+
(_we have no tests for this temporary server!_).
79+
80+
81+
### Step 4: Install `certbot`
2282

2383
> `certbot` installation instructions for various platforms:
2484
https://letsencrypt.org/getting-started
@@ -28,30 +88,37 @@ brew install certbot
2888
```
2989
![bew-install-certbot](https://cloud.githubusercontent.com/assets/194400/23254553/59f014a0-f9b0-11e6-9667-4e5e9b8014bc.png)
3090

31-
(_might take a few minutes to install on a slower internet connection...
91+
(_it might take a few minutes to install on a slower internet connection...
3292
be patient..._)
3393

34-
### Step 2: Run `certbot` Command (_Manual Setup_)
94+
### Step 4: Run `certbot` Command (_Manual Setup_)
3595

3696
Once you've installed `certbot` run the following command:
3797
```sh
3898
sudo certbot certonly --manual
3999
```
40100

41-
Top-tip you will want to use both the domain an `www` subdomain:
101+
Remember to use both the domain a `www` subdomain. (_separated by a space_) e.g:
42102

103+
```
104+
example.com www.example.com
105+
```
106+
107+
Our app was:
43108
```
44109
healthlocker.uk www.healthlocker.uk
45110
```
46111

47112
Follow the steps and **pay _close_ attention**!
48113

49-
Enter the
50-
51114
When you reach the screen that looks like this:
115+
52116
![certbot-instructions](https://cloud.githubusercontent.com/assets/194400/23255249/c7d2b250-f9b2-11e6-9d45-d2cdb965defa.png)
53117

54-
Instructions: (_for reference ONLY see below for modified instructions_)
118+
_**DON'T** `continue` until you have completed **Step 5**_.
119+
120+
Instructions printed by `certbot`:
121+
(_for reference ONLY see below for sub-set of instructions_)
55122
```
56123
mkdir -p /tmp/certbot/public_html/.well-known/acme-challenge
57124
cd /tmp/certbot/public_html
@@ -64,62 +131,47 @@ s = BaseHTTPServer.HTTPServer(('', 80), SimpleHTTPServer.SimpleHTTPRequestHandle
64131
s.serve_forever()"
65132
```
66133

67-
You _wont_ be _able_ to run shell commands on the Heroku instance
134+
You _wont_ be _able_ to run shell commands on a Heroku instance
68135
so we need to use a _temporary_ node.js server to achieve our objective.
69136

70137
In your `current working directory` (_on your localhost_)
71138
run the following command to create the `.well-known/acme-challenge` directory:
72139

140+
#### Step 4.1 Create the `.well-known/acme-challenge` Directory (_if it doesn't exist_)
141+
73142
```
74143
mkdir -p .well-known/acme-challenge
75144
```
76145

146+
#### Step 4.2 Create a File for the Token Verification
147+
77148
Now ***copy-paste*** the `printf` command from the `certbot` instructions:
78149
they should look _something_ like this:
79150

80151
```
81152
printf "%s" WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0.kURQ5HbILtRXEwJA2QI4W5TdBkjnZNqH2_RHORvmN6w > .well-known/acme-challenge/WgFpodyij_PDzkU0MZ3CzKCI05hjLOcq2tP-1rs6ko0
82153
```
83154
The tokens will be _specific_ to you so make sure you get the correct tokens.
155+
(_there is one token per domain_)
84156

85-
### Step 3: Set Git Remote
157+
#### Step 4.3: Commit Your Changes (_the token file_) and Push to GitHub
86158

87-
Check what your _current_ `origin` remote is:
88-
```sh
89-
git remote -v
90-
```
91-
![git-remote](https://cloud.githubusercontent.com/assets/194400/23256452/7318d01e-f9b7-11e6-94cb-d5450d1addea.png)
159+
Make a commit on your local branch so you can push to github
160+
(_and trigger the heroku build_)
92161

93-
Set it to what ever the git url is for the app you are setting up SSL for. e.g:
94-
```sh
95-
git remote set-url origin git@github.com:healthlocker/healthlocker.git
96162
```
97-
98-
Push your current branch to the GitHub repo:
99-
```sh
100-
git push --set-upstream origin letsencrypt-temporary-server
163+
git add .
164+
git commit -m 'add letsencrypt verification file'
165+
git push
101166
```
167+
That will deploy the file you created in Step 4.2 to Heroku.
102168

103-
### Step 4: _Temporarily_ Change the Branch Heroku Deploys from
104-
105-
![ssl1](https://cloud.githubusercontent.com/assets/194400/23256626/22f87da4-f9b8-11e6-96d1-72e50ebeffa4.png)
106-
107-
Change it to the name of your branch e.g:
108-
109-
![ssl2](https://cloud.githubusercontent.com/assets/194400/23256625/22f75cee-f9b8-11e6-896f-296e353429be.png)
110-
111-
It should look something like this:
169+
### Step 5: Visit the Endpoint in your Browser to _Confirm_ it _Worked_:
112170

113-
![ssl-deploy-from-diff-branch-disable-ci-check](https://cloud.githubusercontent.com/assets/194400/23256955/7e62225c-f9b9-11e6-9ba0-74e5d2644f8a.png)
114-
remember to (_temporarily_) _dissable_ the checkbox `Wait for CI to
115-
pass before deploy` (_we have no tests for this temporary server!_).
171+
Visit your app in a web browser to confirm the deploy worked.
172+
e.g: http://example.com/.well-known/acme-challenge
116173

117-
make a commit on your local branch so you can push to github (_and trigger the heroku build_)
118-
119-
120-
### Step 5: Visit the Endpoint in your Browser to confirm it worked:
121-
122-
our is: http://healthlocker.uk/.well-known/acme-challenge/
174+
The url for _our_ app was: http://healthlocker.uk/.well-known/acme-challenge
123175

124176
![click-on-filename-to-test](https://cloud.githubusercontent.com/assets/194400/23293421/eda79e68-fa5d-11e6-95d4-a8c57fe4a8fd.png)
125177

@@ -222,9 +274,15 @@ Restore the `default` branch for deployment on Heroku:
222274
<br /> <br /><br /> <br />
223275

224276

225-
## Trouble-Shooting
277+
# Trouble-Shooting (_if it doesn't work!_)
278+
279+
The _first_ time I tried to run the `certbot` command, _nothing_ worked!
280+
E.g: the Build failed on Heroku, the cert process failed (_see below_).
281+
This is a catalog of the Trouble-Shooting we did.
226282

227-
The _first_ time I tried this the build ***failed***:
283+
> _As always, if you get stuck,
284+
[**ask a question**](https://github.com/dwyl/learn-heroku/issues)
285+
we will try our best to help!_
228286

229287
![heroku-activity-log-fail](https://cloud.githubusercontent.com/assets/194400/23256822/026ec3a8-f9b9-11e6-9c4b-c26af4276426.png)
230288

@@ -272,7 +330,11 @@ I deleted all the files created in the process and started from scratch ...
272330
Failed again: <br />
273331
![fail again](https://cloud.githubusercontent.com/assets/194400/23263831/4c5070d4-f9d7-11e6-8559-57b2aa714b26.png)
274332

275-
Just keep trying ...
333+
Re-trace your steps and make sure you followed the instructions _exactly_.
334+
Also, timing matters. if you take a break between steps
335+
you will get a "Time Out Error"...
336+
We initially got it wrong,
337+
but after re-running the command it works as expected.
276338

277339

278340
#### If you get a _Certificate Warning_ in Step 7.8
@@ -302,6 +364,10 @@ After running `certbot` _another_ time, it worked. :rocket:
302364

303365
## Background Reading
304366

367+
+ An introduction to SSL certificates:
368+
https://woocommerce.com/2015/12/ssl-certificates-for-ecommerce
369+
+ Public Key Certificate: https://en.wikipedia.org/wiki/Public_key_certificate
370+
+ Transport Layer Security: https://en.wikipedia.org/wiki/Transport_Layer_Security
305371
+ Certbot Manual mode: https://certbot.eff.org/docs/using.html#manual
306372
+ Inspiration tutorial (_Ruby-on-Rails focussed_):
307373
https://collectiveidea.com/blog/archives/2016/01/12/lets-encrypt-with-a-rails-app-on-heroku

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"live-server": "^1.2.0"
77
},
88
"engines": {
9-
"node": "6.10.x",
10-
"npm": "1.2.x"
9+
"node": "6.10.x"
1110
},
1211
"scripts": {
1312
"start": "node node_modules/.bin/http-server",

0 commit comments

Comments
 (0)