@@ -316,3 +316,108 @@ sure the certificate changes after 74-80 seconds.
316
316
``` sh
317
317
certificates $ step certificate inspect --insecure https://localhost:8443
318
318
```
319
+
320
+ ## NGINX with Step CA certificates
321
+
322
+ The example under the ` docker ` directory shows how to combine the Smallstep CA
323
+ with NGINX to server pages or proxy services using certificates created by the
324
+ step-ca.
325
+
326
+ This example creates 3 different docker images:
327
+
328
+ * nginx-test: docker image with NGINX and a script using inotify-tools to watch
329
+ for changes in the certificate to reload NGINX.
330
+ * step-ca-test: docker image with the Smallstep CA
331
+ * step-renewer-test: docker images with the step cli tool, it creates the
332
+ certificate and has a cron that renews the certificate. Right now the cron
333
+ runs every minute for testing purposes.
334
+
335
+ To run this test you need to have docker daemon running. With docker running
336
+ swith to the ` examples/docker directory ` and just run ` make `
337
+
338
+ ``` sh
339
+ certificates $ cd examples/docker/
340
+ docker $ make
341
+ ```
342
+
343
+ Make will build the binaries for step and step-ca, create the images, and deploy
344
+ them using docker composer.
345
+
346
+ NGINX will be listening on your local machine on https://localhost:4443 , but to
347
+ make sure the cert is right we need to add the following entry to ` /etc/hosts ` :
348
+
349
+ ```
350
+ 127.0.0.1 nginx
351
+ ```
352
+
353
+ Now we can use curl to check:
354
+
355
+ ``` sh
356
+ docker $ curl --cacert ca/pki/secrets/root_ca.crt https://nginx:4443/
357
+ < ! DOCTYPE html>
358
+ < html>
359
+ < head>
360
+ < title> Welcome to nginx! < /title>
361
+ < style>
362
+ body {
363
+ width: 35em;
364
+ margin: 0 auto;
365
+ font-family: Tahoma, Verdana, Arial, sans-serif;
366
+ }
367
+ < /style>
368
+ < /head>
369
+ < body>
370
+ < h1> Welcome to nginx! < /h1>
371
+ < p> If you see this page, the nginx web server is successfully installed and
372
+ working. Further configuration is required.< /p>
373
+
374
+ < p> For online documentation and support please refer to
375
+ < a href=" http://nginx.org/" > nginx.org< /a> .< br/>
376
+ Commercial support is available at
377
+ < a href=" http://nginx.com/" > nginx.com< /a> .< /p>
378
+
379
+ < p><em> Thank you for using nginx.< /em></p>
380
+ < /body>
381
+ < /html>
382
+ ```
383
+
384
+ Now you can use ` make inspect ` to inspect the certificate to see how the
385
+ certificate gets updated every minute:
386
+
387
+ ``` sh
388
+ docker $ make inspect
389
+ step certificate inspect https://localhost:4443 --insecure
390
+ Certificate:
391
+ Data:
392
+ Version: 3 (0x2)
393
+ Serial Number: 220353801925419530569669982276277771655 (0xa5c6993a7e110e6f009c83c79edc1d87)
394
+ Signature Algorithm: ECDSA-SHA256
395
+ Issuer: CN=Smallstep Intermediate CA
396
+ Validity
397
+ Not Before: Nov 10 02:13:00 2018 UTC
398
+ Not After : Nov 11 02:13:00 2018 UTC
399
+ mariano@endor docker (docker-nginx)* $ make inspect | head
400
+ step certificate inspect https://localhost:4443 --insecure
401
+ Certificate:
402
+ Data:
403
+ Version: 3 (0x2)
404
+ Serial Number: 207756171799719353821615361892302471392 (0x9c4c621c04d3e8be401ff0d14c5440e0)
405
+ Signature Algorithm: ECDSA-SHA256
406
+ Issuer: CN=Smallstep Intermediate CA
407
+ Validity
408
+ Not Before: Nov 10 02:14:00 2018 UTC
409
+ Not After : Nov 11 02:14:00 2018 UTC
410
+ ```
411
+
412
+ Finally, to remove the containers and volumes you can use ` make clean ` :
413
+
414
+ ``` sh
415
+ docker $ make clean
416
+ docker service rm steplab_ca steplab_nginx steplab_renewer
417
+ steplab_ca
418
+ steplab_nginx
419
+ steplab_renewer
420
+ sleep 20
421
+ docker volume rm -f steplab_certificates
422
+ steplab_certificates
423
+ ```
0 commit comments