Enabling SSL for Self Hosted Nancy

One of the things I like about Nancy is the ease of creating self hosted HTTP services.

Here’s how to enable HTTPS for your service.

First of all, create your SSL certificate:

$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem
$ openssl pkcs12 -export -in cert.pem -inkey key.pem -out mycert.pfx

Then go to ‘Manage Computer Certificates’ in the start menu (I’m using Windows 8.1).

Right click on ‘Personal’ and import the freshly created mycert.pfx.


Now go to your newly installed certificate, and get the thumbprint:


Now you need to register the URL with Windows:

$ netsh http add urlacl url=https://+:4443/ user=YOUR_USERNAME
$ netsh http add sslcert ipport= certhash=‎YOUR_THUMBPRINT_WITHOUT_SPACES appid={06aabebd-3a91-4b80-8a15-adfd3c8a0b14} 

You need to substitute your username, and the certificate thumbprint you copied (without the spaces)

The appid is just a random guid, feel free to create your own.

Now start nancy on this Uri https://localhost:4443/.

using (var host = new NancyHost(new Uri("https://localhost:4443/")))