运行自包含的.net-core可执行文件无响应请求

时间:2017-07-02 12:13:03

标签: asp.net-mvc .net-core

我正在按照教程编写一个.net独立应用程序并将其发送到我的Ubuntu 16.10服务器。现在我正在运行应用程序,一切似乎都正常工作

$ ./MvcMovie
Hosting environment: Production
Content root path: /home/nnkuu/CEPublished/publish
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

但是当我尝试通过http:// SERVER_IP:5000上的Web浏览器访问服务器时,浏览器无法建立连接。我做错了什么?

2 个答案:

答案 0 :(得分:2)

问题是服务器正在监听http://localhost:5000。这意味着如果您从与http://localhost:5000相同的计算机访问该应用程序,它将起作用,但如果您从另一台计算机访问该计算机,它将无法运行。

您需要做的是更改应用正在侦听的网址。最简单的方法是将以下行添加到WebHostBuilder方法中的main设置中:

.UseUrls("http://*:5000")

答案 1 :(得分:1)

我通过将nginx函数作为代理来解决问题,该代理将来自外部接口上的端口80的流量转发到.net应用程序正在侦听的内部接口上的端口5000。这是通过使用以下配置文件运行nginx来完成的:

# Default server configuration
#
server {
    listen 80;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name <server_name or IP address>;

    location / {
              proxy_pass http://127.0.0.1:5000;
    }
}