Nancyfx self hosting over HTTPS

人走茶凉 提交于 2019-12-21 02:36:17

问题


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.


回答1:


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!




回答2:


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/



来源:https://stackoverflow.com/questions/27553633/nancyfx-self-hosting-over-https

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!