@@ -36,7 +36,8 @@ Nginx and Let’s Encrypt with Docker Compose in less than 3 minutes.
36
36
37
37
This example automatically obtains and renews [ Let's Encrypt] ( https://letsencrypt.org/ ) free SSL/TLS certificates and sets up HTTPS in Nginx for multiple domain names using Docker Compose.
38
38
39
- You can run Nginx with IPv4, IPv6, HTTP/1.1, and HTTP/2 support and set up HTTPS with Let's Encrypt TLS certificates for your domain names and get an A+ rating in [ SSL Labs SSL Server Test] ( https://www.ssllabs.com/ssltest/ ) using Docker Compose and _ letsencrypt-docker-compose_ interactive CLI tool.
39
+ You can run Nginx and set up HTTPS (` https:// ` ) and WebSocket Secure (` wss:// ` ) with Let's Encrypt TLS certificates for your domain names and get an A+ rating in [ SSL Labs SSL Server Test] ( https://www.ssllabs.com/ssltest/ ) using Docker Compose and _ letsencrypt-docker-compose_ interactive CLI tool.
40
+ Nginx is configured to support IPv4, IPv6, HTTP/1.1, HTTP/2, and optionally, WebSocket.
40
41
41
42
Let's Encrypt is a certificate authority that provides free X.509 certificates for TLS encryption.
42
43
The certificates are valid for 90 days and can be renewed. Both initial creation and renewal can be automated using [ Certbot] ( https://certbot.eff.org/ ) .
@@ -116,6 +117,8 @@ cp -R ./examples/html/ ./html/a.evgeniy-khyst.com
116
117
117
118
The [ ` docker-compose.yml ` ] ( docker-compose.yml ) contains the ` example-backend ` service.
118
119
It's a simple Node.js web app listening on port 8080.
120
+ It has ` /hello?name={name} ` REST endpoint and WebSocket echo server sending back the request sent by the client.
121
+
119
122
Replace it with your backend service or remove it.
120
123
121
124
``` yaml
@@ -155,6 +158,12 @@ networks:
155
158
156
159
Run the CLI tool and follow the instructions to perform an initial setup.
157
160
161
+ ` ` ` bash
162
+ ./cli.sh config
163
+ ` ` `
164
+
165
+ or
166
+
158
167
` ` ` bash
159
168
docker compose run --rm cli
160
169
` ` `
@@ -166,14 +175,26 @@ We will switch to a Let's Encrypt production environment after verifying that HT
166
175
167
176
# ## <a id="2-5"></a>Step 4 - Start the services
168
177
169
- On the first run, build the services.
178
+ If you've made any changes to the Docker images, rebuild the services.
179
+
180
+ ` ` ` bash
181
+ ./cli.sh build
182
+ ` ` `
183
+
184
+ or
170
185
171
186
` ` ` bash
172
187
docker compose build
173
188
` ` `
174
189
175
190
Start the services.
176
191
192
+ ` ` ` bash
193
+ ./cli.sh up
194
+ ` ` `
195
+
196
+ or
197
+
177
198
` ` ` bash
178
199
docker compose up -d
179
200
` ` `
@@ -193,7 +214,7 @@ Reloading Nginx configuration
193
214
194
215
# ## <a id="2-6"></a>Step 5 - Verify that HTTPS works with the test certificates
195
216
196
- For each domain, check `https://${domain}` and `https://www.${domain}` if you configured the `www` subdomain.
217
+ For each domain, check `https://${domain}` and `https://www.${domain}` if you've configured the `www` subdomain.
197
218
Certificates issued by `(STAGING) Let's Encrypt` are considered not secure by browsers and cURL.
198
219
199
220
` ` ` bash
@@ -203,10 +224,22 @@ curl --insecure https://b.evgeniy-khyst.com/hello?name=Eugene
203
224
curl --insecure https://www.b.evgeniy-khyst.com/hello?name=Eugene
204
225
` ` `
205
226
227
+ If you've set up WebSocket, check it using the [wscat](https://github.com/websockets/wscat) tool.
228
+
229
+ ` ` ` bash
230
+ wscat --no-check --connect wss://b.evgeniy-khyst.com/echo
231
+ ` ` `
232
+
206
233
# ## <a id="2-7"></a>Step 6 - Switch to a Let's Encrypt production environment
207
234
208
235
Run the CLI tool, choose `Switch to a Let's Encrypt production environment` and follow the instructions.
209
236
237
+ ` ` ` bash
238
+ ./cli.sh config
239
+ ` ` `
240
+
241
+ or
242
+
210
243
` ` ` bash
211
244
docker compose run --rm cli
212
245
` ` `
@@ -215,7 +248,7 @@ docker compose run --rm cli
215
248
216
249
# ## <a id="2-8"></a>Step 7 - Verify that HTTPS works with the production certificates
217
250
218
- For each domain, check `https://${domain}` and `https://www.${domain}` if you configured the `www` subdomain.
251
+ For each domain, check `https://${domain}` and `https://www.${domain}` if you've configured the `www` subdomain.
219
252
Certificates issued by `Let's Encrypt` are considered secure by browsers and cURL.
220
253
221
254
` ` ` bash
@@ -225,6 +258,12 @@ curl https://b.evgeniy-khyst.com/hello?name=Eugene
225
258
curl https://www.b.evgeniy-khyst.com/hello?name=Eugene
226
259
` ` `
227
260
261
+ If you've set up WebSocket, check it using the [wscat](https://github.com/websockets/wscat) tool.
262
+
263
+ ` ` ` bash
264
+ wscat --connect wss://b.evgeniy-khyst.com/echo
265
+ ` ` `
266
+
228
267
Optionally check your domains with [SSL Labs SSL Server Test](https://www.ssllabs.com/ssltest/) and review the SSL Reports.
229
268
230
269
The `cron` service will automatically renew the Let's Encrypt production certificates when the time comes.
@@ -254,20 +293,32 @@ Repeat the actions described in [the subsection of the same name in the "Initial
254
293
255
294
Run the CLI tool, choose `Add new domains` and follow the instructions.
256
295
296
+ ` ` ` bash
297
+ ./cli.sh config
298
+ ` ` `
299
+
300
+ or
301
+
257
302
` ` ` bash
258
303
docker compose run --rm cli
259
304
` ` `
260
305
261
306
# ## <a id="3-4"></a>Step 4 - Verify that HTTPS works
262
307
263
- For each new domain, check `https://${domain}` and `https://www.${domain}` if you configured the `www` subdomain.
308
+ For each new domain, check `https://${domain}` and `https://www.${domain}` if you've configured the `www` subdomain.
264
309
265
310
[Back to top](#0)
266
311
267
312
# # <a id="4"></a>Removing existing domains without downtime
268
313
269
314
Run the CLI tool, choose `Remove existing domains` and follow the instructions.
270
315
316
+ ` ` ` bash
317
+ ./cli.sh config
318
+ ` ` `
319
+
320
+ or
321
+
271
322
` ` ` bash
272
323
docker compose run --rm cli
273
324
` ` `
@@ -284,6 +335,12 @@ This operation is not appropriate to run daily because each certificate will be
284
335
285
336
Run the CLI tool, choose `Manually renew all Let's Encrypt certificates (force renewal)` and follow the instructions.
286
337
338
+ ` ` ` bash
339
+ ./cli.sh config
340
+ ` ` `
341
+
342
+ or
343
+
287
344
` ` ` bash
288
345
docker compose run --rm cli
289
346
` ` `
@@ -300,13 +357,23 @@ It is possible in dry run mode.
300
357
301
358
# ## <a id="6-1"></a>Step 1 - Perform an initial setup using the CLI tool
302
359
360
+ ` ` ` bash
361
+ ./cli.sh config
362
+ ` ` `
363
+
364
+ or
365
+
303
366
` ` ` bash
304
367
docker compose run --rm cli
305
368
` ` `
306
369
307
370
# ## <a id="6-2"></a>Step 2 - Start the services in dry run mode
308
371
309
- Enable dry run mode by setting the environment variable `DRY_RUN=true`.
372
+ ` ` ` bash
373
+ ./cli.sh up --dry-run
374
+ ` ` `
375
+
376
+ Alternatively, you can enable dry run mode using the environment variable `DRY_RUN=true`.
310
377
311
378
` ` ` bash
312
379
DRY_RUN=true docker compose up -d
@@ -332,9 +399,16 @@ upstream backend {
332
399
```
333
400
334
401
After editing the Nginx configuration, do a hot reload of the Nginx configuration.
402
+ Run the CLI tool and choose `Reload Nginx configuration without downtime`.
403
+
404
+ ```bash
405
+ ./cli.sh config
406
+ ```
407
+
408
+ or
335
409
336
410
``` bash
337
- docker compose exec --no-TTY nginx nginx -s reload
411
+ docker compose run --rm cli
338
412
```
339
413
340
414
Manual edits of the ` nginx-conf/nginx.conf ` and ` nginx-conf/conf.d/${domain}.conf ` are lost after running the CLI tool
@@ -346,6 +420,14 @@ To make Nginx configuration changes persistent, also edit the Handlebars templat
346
420
- [ ` templates/nginx.conf.hbs ` ] ( templates/nginx.conf.hbs ) ,
347
421
- [ ` templates/servers.conf.hbs ` ] ( templates/servers.conf.hbs ) .
348
422
423
+ To add domain-specific configuration to a template use the [ ` ifEquals ` Handlebars helper] ( cli/src/handlebars-helpers.js ) .
424
+
425
+ ``` hbs
426
+ {{#ifEquals domain "a.evgeniy-khyst.com"}}
427
+ # Configuration for a specific domain
428
+ {{/ifEquals}}
429
+ ```
430
+
349
431
[ Back to top] ( #0 )
350
432
351
433
## <a id =" 8 " ></a >Running Docker containers as a non-root user
@@ -377,6 +459,18 @@ Run the CLI tool specifying the current user and `docker` group to make it creat
377
459
CURRENT_USER=" $( id -u) :$( id -g) " DOCKER_GROUP=" $( getent group docker | cut -d: -f3) " docker compose run --rm cli
378
460
```
379
461
462
+ The convenience script ` cli.sh ` runs the CLI tool as the current user by default.
463
+
464
+ ``` bash
465
+ ./cli.sh config
466
+ ```
467
+
468
+ You can run the CLI tool as UID/GID 0 instead of the current user with the option ` --no-current-user ` .
469
+
470
+ ``` bash
471
+ ./cli.sh config --no-current-user
472
+ ```
473
+
380
474
[ Back to top] ( #0 )
381
475
382
476
## <a id =" 9 " ></a >SSL configuration for A+ rating
0 commit comments