Skip to content

How to launch a secure local web server (HTTPS)

Lloyd Brookes edited this page Jul 8, 2017 · 6 revisions

Some modern techs (HTTP2, ServiceWorker, MediaDevices.getUserMedia() etc.) must be served from a secure origin (HTTPS). To launch an HTTPS server, you must supply either:

  • the --https flag
  • --key and --cert files
  • a --pfx file

The quickest method is to use the https flag, this will use the private key and certificate chain supplied with local-web-server. This example will serve your current project as a secure, static web site.

  1. Install local-web-server
$ npm install -g local-web-server
  1. Navigate into to your project
$ cd example-project
  1. Launch the secure webserver.
$ ws --https
Serving at https://mbp.local:8000, https://127.0.0.1:8000, https://192.168.0.100:8000
  1. Navigating to one of the listed URLs will render a directory listing or your index.html, if that file exists.

Next, read the guide on how to get the "green lock".

Clone this wiki locally