2017-07-02 15 views
1

我正在學習一個教程,並編譯了一個.net獨立應用程序並將其發送到我的Ubuntu 16.10服務器。現在我運行的應用程序,一切似乎正常工作運行自包含.net-core可執行文件無響應請求

$ ./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,瀏覽器無法建立連接。我究竟做錯了什麼?

回答

1

我通過使nginx的功能,從端口80的外部接口上轉發流量到5000端口上的代理解決了這個問題.net應用程序正在偵聽的內部接口。這是通過運行帶有以下配置文件的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; 
    } 
} 
2

問題是服務器正在監聽http://localhost:5000。這意味着如果您從http://localhost:5000的同一臺機器訪問該應用程序,它將起作用,但如果您從另一臺機器訪問它,它將不起作用。

你需要做的是更改應用程序正在監聽的URL。最簡單的方法是將下面的行添加到WebHostBuilder設置在main方法:

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

謝謝。不過,我最終使用nginx將內部外部網絡接口的請求轉發到內部。 –