How do I get the kestrel web server to listen to non-localhost requests?

前端 未结 6 1099
日久生厌
日久生厌 2020-11-27 10:39

I\'ve deployed my c#, asp.net 5, mvc 6 app to a windows 2008 server. I\'ve fired up dnx web and it is listening to port 5000 and works fine when accessing from

6条回答
  •  清歌不尽
    2020-11-27 11:27

    If you are trying to put an ASP.NET Core application inside a docker container (which was my use case for needing to listen to non-localhost addresses), note that this use case has already been put together for you by Microsoft. You can see the full glory at https://hub.docker.com/r/microsoft/aspnetcore/

    At current (v1.0.1) the key magic for solving this problem is that the source Dockerfile contains a url environment variable setting, and the application does not attempt to override this. (Indeed, a containerized application should internally assert as little as possible about the environment where it will run.)

    ENV ASPNETCORE_URLS http://+:80
    

    Note the plus sign rather than asterisk there. I actually recommend visiting the above dockerhub link over reading my answer for as long as the link is good. Version 1.1 is just around the corner, and things may change again in the future.

    When running the container, make sure to expose guest port 80, per the environment variable setting. For example:

    docker run -d -p 8000:80 myapp
    curl localhost:8000
    

提交回复
热议问题