Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nancyfx self hosting over HTTPS

Tags:

c#

https

nancy

I tried to start a nancyfx webserver in self hosting mode. Everything works fine when executing the following code:

 public static void Main(string[] args)
 {
        var hostConfig = new HostConfiguration
        {
            UrlReservations = new UrlReservations
            { 
                CreateAutomatically = true
            },        
        };

        var host = new NancyHost(hostConfig, new Uri("http://localhost:8081"));
        host.Start();

        Console.ReadLine();

        host.Stop();
}

However, when I change the uri to https://... the server starts but every connection opened by the browser is instantly closed and the browser displays "The website is not available". The connection is even closed before the browser would close the connection due to a timeout.

I am running the application with .NET 4.5 on Windows. Using netstat -a I can tell that the right port is opened.

Am I missing something? Thanks for your help.

like image 327
Scyman Avatar asked Dec 01 '22 00:12

Scyman


2 Answers

I've got it working. I've found it useful to have a number of checks in the process.

CHECK1 - Was the certificate added correctly? (using Certificate Management MMC snap-in correctly):

  • After you install the cert on the machine run certutil -store MY
  • You should see the cert details there (sha/user created/name etc)
  • If not STOP. You probably imported into the user store (or the cert is invalid). You MUST start with empty mmc and import certificates for the MACHINE.

CHECK2 - Was the url added to urlacl list in netsh correctly? (using netsh http add urlacl)?:

  • After you add the uri to acl run netsh http show urlacl
  • If your uri / port is not listed STOP. The url isn't added correctly.

CHECK3 - Was ssl bound to urlacl ? (using netsh http add sslcert)

  • After running the add sslcert command run netsh http show sslcert
  • If your port/sha combination is not listed then check the sha has no spaces / appid is unique / app id + braces surrounded by quotes (if executing from PS)

Hope it helps. I created the above after 6 hours of head banging. It now works!

like image 96
penderi Avatar answered Dec 09 '22 23:12

penderi


maybe you missed SSL cert config and url acl config.

Check this post : https://coderead.wordpress.com/2014/08/07/enabling-ssl-for-self-hosted-nancy/

like image 34
wafe Avatar answered Dec 09 '22 23:12

wafe