2015-07-08 06:43:46 +00:00
|
|
|
serve-https
|
|
|
|
===========
|
|
|
|
|
2015-07-08 07:46:01 +00:00
|
|
|
A simple HTTPS static file server with valid TLS (SSL) certs.
|
2015-07-08 06:43:46 +00:00
|
|
|
|
2015-07-08 07:46:01 +00:00
|
|
|
Comes bundled a valid certificate for localhost.daplie.com,
|
|
|
|
which is great for testing and development, and you can specify your own.
|
2015-06-30 23:11:01 +00:00
|
|
|
|
2015-07-08 06:43:46 +00:00
|
|
|
Also great for testing ACME certs from letsencrypt.org.
|
2015-06-24 21:44:42 +00:00
|
|
|
|
|
|
|
Install
|
|
|
|
-------
|
|
|
|
|
|
|
|
```bash
|
|
|
|
npm install --global serve-https
|
|
|
|
serve-https
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
2015-07-08 06:45:40 +00:00
|
|
|
Serving /Users/foo/ at https://localhost.daplie.com:8443
|
2015-06-24 21:44:42 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
2015-07-08 06:45:40 +00:00
|
|
|
* `-p <port>` - i.e. `sudo serve-https -p 443` (defaults to 8443)
|
|
|
|
* `-d <dirpath>` - i.e. `serve-https -d /tmp/` (defaults to `pwd`)
|
|
|
|
* `-c <content>` - i.e. `server-https -c 'Hello, World! '` (defaults to directory index)
|
|
|
|
* `--insecure-port <port>` - run an http server that redirects to https (off by default)
|
2015-07-08 06:43:46 +00:00
|
|
|
|
|
|
|
Specifying a custom HTTPS certificate:
|
|
|
|
|
2015-07-08 07:46:01 +00:00
|
|
|
* `--key /path/to/privkey.pem` specifies the server private key
|
|
|
|
* `--cert /path/to/cert.pem` specifies the server certificate
|
|
|
|
* `--chain /path/to/chain.pem` specifies the certificate authorities
|
2015-07-08 06:43:46 +00:00
|
|
|
|
2015-07-08 07:46:01 +00:00
|
|
|
Note: `--chain` may specify single cert, a bundle, and may be used multiple times like so:
|
|
|
|
|
|
|
|
```
|
|
|
|
--chain /path/to/intermediate-ca-1.pem --chain /path/to/intermediate-ca-2.pem
|
|
|
|
```
|
|
|
|
|
|
|
|
Other options:
|
|
|
|
|
|
|
|
* `--serve-chain true` alias for `-c` with the contents of chain.pem
|
|
|
|
* `--servername example.com` changes the servername logged to the console
|
|
|
|
* `--letsencrypt-certs example.com` sets and key, cert, and chain to standard letsencrypt locations
|
2015-06-30 23:11:01 +00:00
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
|
|
|
```bash
|
|
|
|
serve-https -p 1443 -c 'Hello from 1443' &
|
|
|
|
serve-https -p 2443 -c 'Hello from 2443' &
|
2015-07-08 06:43:46 +00:00
|
|
|
serve-https -p 3443 -d /tmp --insecure-port 4080 &
|
2015-06-30 23:11:01 +00:00
|
|
|
|
|
|
|
curl https://localhost.daplie.com:1443
|
|
|
|
> Hello from 1443
|
|
|
|
|
|
|
|
curl --insecure https://localhost:2443
|
|
|
|
> Hello from 2443
|
|
|
|
|
|
|
|
curl https://localhost.daplie.com:3443
|
|
|
|
> [html index listing of /tmp]
|
|
|
|
```
|
2015-07-08 06:43:46 +00:00
|
|
|
|
|
|
|
And if you tested <http://localhost.daplie.com:4080> in a browser,
|
|
|
|
it would redirect to <https://localhost.daplie.com:3443>.
|
|
|
|
|
|
|
|
(in curl it would just show an error message)
|
|
|
|
|
|
|
|
### Testing ACME Let's Encrypt certs
|
|
|
|
|
2015-07-08 06:51:38 +00:00
|
|
|
In case you didn't know, you can get free https certificates from
|
|
|
|
[letsencrypt.org](https://letsencrypt.org)
|
2015-07-08 06:48:18 +00:00
|
|
|
(ACME letsencrypt)
|
|
|
|
and even a free subdomain from <https://freedns.afraid.org>.
|
2015-07-08 06:43:46 +00:00
|
|
|
|
2015-07-08 06:51:38 +00:00
|
|
|
If you want to quickly test the certificates you installed,
|
|
|
|
you can do so like this:
|
|
|
|
|
2015-07-08 06:43:46 +00:00
|
|
|
```bash
|
2015-07-08 07:27:14 +00:00
|
|
|
sudo serve-https -p 8443 \
|
|
|
|
--letsencrypt-certs test.mooo.com \
|
|
|
|
--serve-chain true
|
|
|
|
```
|
|
|
|
|
|
|
|
which is equilavent to
|
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo serve-https -p 8443 \
|
|
|
|
--servername test.mooo.com
|
2015-07-08 06:43:46 +00:00
|
|
|
--key /etc/letsencrypt/live/test.mooo.com/privkey.pem \
|
|
|
|
--cert /etc/letsencrypt/live/test.mooo.com/cert.pem \
|
|
|
|
--chain /etc/letsencrypt/live/test.mooo.com/chain.pem \
|
2015-07-08 07:27:14 +00:00
|
|
|
-c "$(cat 'sudo /etc/letsencrypt/live/test.mooo.com/chain.pem')"
|
2015-07-08 06:43:46 +00:00
|
|
|
```
|
|
|
|
|
2015-07-08 07:27:14 +00:00
|
|
|
and can be tested like so
|
|
|
|
|
2015-07-08 06:43:46 +00:00
|
|
|
```bash
|
|
|
|
curl --insecure https://test.mooo.com:8443 > ./chain.pem
|
|
|
|
curl https://test.mooo.com:8843 --cacert ./chain.pem
|
|
|
|
```
|
|
|
|
|
|
|
|
* [QuickStart Guide for Let's Encrypt](https://coolaj86.com/articles/lets-encrypt-on-raspberry-pi/)
|
|
|
|
* [QuickStart Guide for FreeDNS](https://coolaj86.com/articles/free-dns-hosting-with-freedns-afraid-org.html)
|