Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify the host #3

Closed
luebken opened this issue Jun 11, 2015 · 14 comments
Closed

How to specify the host #3

luebken opened this issue Jun 11, 2015 · 14 comments

Comments

@luebken
Copy link
Owner

luebken commented Jun 11, 2015

Mono / Nancy seems to require set the hostname. But if I hardcoded it:

            var port = 8080;
            var nancyHost = new NancyHost(new Uri("http://nancy-luebken.gigantic.io:" + port));
            nancyHost.Start();

I can't bind it:

2015-06-11 09:41:18.894 +0000 UTC    - docker  - Status: Image is up to date for registry.giantswarm.io/luebken/nancy:latest
2015-06-11 09:41:20.579 +0000 UTC    - docker  - Unhandled Exception:
2015-06-11 09:41:20.58 +0000 UTC     - docker  - at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.58 +0000 UTC     - docker  - at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.58 +0000 UTC     - docker  - System.Net.Sockets.SocketException: The requested address is not valid in this context
2015-06-11 09:41:20.58 +0000 UTC     - docker  - at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.581 +0000 UTC    - docker  - at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.581 +0000 UTC    - docker  - at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.582 +0000 UTC    - docker  - at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.582 +0000 UTC    - docker  - [ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: The requested address is not valid in this context
2015-06-11 09:41:20.582 +0000 UTC    - docker  - at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.583 +0000 UTC    - docker  - at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.583 +0000 UTC    - docker  - at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-11 09:41:20.584 +0000 UTC    - docker  - at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00000] in <filename unknown>:0

swarm.json see:
https://github.com/luebken/nancy-demo-hosting-docker/blob/swarmify/swarm.json

@zeisss
Copy link

zeisss commented Jun 11, 2015

If thats the adress to bind to, you can use "0.0.0.0:" + port

@zeisss
Copy link

zeisss commented Jun 11, 2015

btw, he cannot bind to that adress because the DNS lookup for that hostnames gives the IP of our loadbalancer and no local network interface has that IP.

@luebken
Copy link
Owner Author

luebken commented Jun 11, 2015

I can not use "0.0.0.0" since http://nancyfx.org/ is looking at the Host header and cant match it. See for example the workaround for curl & boot2docker where I need to explicity pass the host header:
$ curl -H "Host: 0.0.0.0:8080" $(boot2docker ip):8080
https://github.com/BenHall/nancy-demo-hosting-docker/blob/master/README.md

@zeisss
Copy link

zeisss commented Jun 11, 2015

I guess you need to configure the host value of the bootstrapper slightly. Maybe https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy helps? I can't find any API documentation :(

@luebken
Copy link
Owner Author

luebken commented Jun 11, 2015

Could be. I tried to set fool around with HostConfiguration but my none existing C# knowledge doesn't help. ;-)

This:

namespace Nancy.Demo.Hosting.Docker
{
    using System;
    using System.Diagnostics;

    using Nancy.Hosting.Self;

    class Program
    {
        static void Main()
        {
            var port = 8080;
            var config = new  Nancy.Hosting.Self.HostConfiguration
            {
                UrlReservations = new UrlReservations() { CreateAutomatically = true }
            };

            var nancyHost = new NancyHost(config, new Uri("http://0.0.0.0:" + port));
            nancyHost.Start();

            Console.WriteLine("Nancy now listening on http://0.0.0.0:" + port);

            var line = Console.ReadLine();
            while(line != "quit") {
              line = Console.ReadLine();
            }
        }
    }
}

throws the error

`Program.cs(13,50): error CS0234: The type or namespace name `HostConfiguration' does not exist in the namespace `Nancy.Hosting.Self'. Are you missing an assembly reference?`

which I don't get since it seems in the right namespace: https://github.com/NancyFx/Nancy/blob/master/src/Nancy.Hosting.Self/HostConfiguration.cs

Maybe the included DLL is old.

@zeisss
Copy link

zeisss commented Jun 11, 2015

leave the package. You are already using it. You are not doing it for the NancyHost and that worked.

@luebken
Copy link
Owner Author

luebken commented Jun 11, 2015

That didnt help

            var config = new HostConfiguration();
Program.cs(13,30): error CS0246: The type or namespace name `HostConfiguration' could not be found. Are you missing an assembly reference?

@mmetesreau
Copy link

I had the same issue this afternoon... After some try, I managed to run my nancy webapp without error by using the Katana - HttpListener instead of NancyHost :

 using (WebApp.Start<Startup>(string.Format("http://*:{0}", port)))
 {
  QuitEvent.WaitOne();
}

@luebken
Copy link
Owner Author

luebken commented Jun 22, 2015

@MikAdoo Do you have that running with this or some other repo? I can't get it to run.

@mmetesreau
Copy link

i have submitted a pull request

luebken pushed a commit that referenced this issue Jun 23, 2015
@luebken
Copy link
Owner Author

luebken commented Jun 23, 2015

Thanks for the PR. Works great locally. Unfortunately I can't start it on our hosting. Since I can't bind the address "http://*:{0}" which throws a System.Net.Sockets.SocketException: The requested address is not valid in this context.

015-06-23 14:24:37.26 +0000 UTC     - docker  - System.Net.Sockets.SocketException: The requested address is not valid in this context
2015-06-23 14:24:37.26 +0000 UTC     - docker  - Unhandled Exception:
2015-06-23 14:24:37.26 +0000 UTC     - docker  - at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.26 +0000 UTC     - docker  - at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointListener..ctor (System.Net.IPAddress addr, Int32 port, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.GetEPListener (System.String host, Int32 port, System.Net.HttpListener listener, Boolean secure) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
2015-06-23 14:24:37.261 +0000 UTC    - docker  - [ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: The requested address is not valid in this context

I'm used to bind to all IP addresses via 0.0.0.0. But if I specify that via

            using (WebApp.Start<Startup>(string.Format("http://0.0.0.0:{0}", port)))

I get the error Bad Request (Invalid host) in the browser. No more logs unfortunately.

@mmetesreau
Copy link

Arf.... Before my pull request, I also encountered the bind issue. This morning I tested my update on a digital ocean linux vm and everything worked fine. I made another test right now on my computer on windows, boot2docker and custom hostname in my etc/host and the container still works fine. Could you tell me more about your own environment? Did you try with "http://+:{0}" instead of "http://*:{0}"?

@luebken
Copy link
Owner Author

luebken commented Jun 23, 2015

"http://+:{0}"worked awesome: http://nancy-luebken.gigantic.io/

@MikAdoo Thanks a lot!

@luebken luebken closed this as completed Jun 23, 2015
@mmetesreau
Copy link

Cool! You are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants