![](/img/trans.png)
[英]How to run a ASP.NET Core Web API dll file as a service in Nginx server?
[英]Asp.Net Core Web API app: how to change listening address?
我編寫了簡單的 Asp.Net Core WebAPI 2.0 應用程序,它可以在我的本地機器上運行。 但我想將它部署到服務器。 所以,我這樣做。
我的系統:
Ubuntu 16.04.
Asp.Net WebAPI 2.0 (and dotnet version 2.1.105)
但是,當應用程序啟動時,它寫道:
Now listening on:http://localhost:53115
當我嘗試從中獲取值時:
http://id_address:53115/api/values
我無法得到回應。 在郵遞員中:
Could not get any response
There was an error connecting to
http://id_address:53115/api/values.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General
我該做什么? 你能告訴我如何解決這個問題嗎?
我不知道從哪里開始尋找。
謝謝!
我使用的是 .NETCore 2.1 prev,所以我無法自己測試,但如果我相信https://www.billbogaiv.com/posts/setting-aspnet-host-address-in-net-core -2 ,添加.UseUrls(urls: "http://*:5000")
可能會指示 Kestrel 偵聽端口 5000 而不僅僅是在本地主機上,因此它也應該在遠程服務器上工作。
其他可能的解決方案, UseKestrel(..)
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1&tabs=aspnetcore2x使用IPAddress.Any
而不是Loopback
。
這是由Server urls主機配置配置的
指示服務器應偵聽請求的帶有端口和協議的 IP 地址或主機地址。
關鍵:網址
類型:字符串
默認值: http://localhost:5000
設置使用:UseUrls
環境變量:ASPNETCORE_URLS設置為服務器應響應的 URL 前綴的分號分隔 (;) 列表。
也可以使用命令行參數設置 URL。 例如:
dotnet 運行 --urls= http://0.0.0.0:5001
但這不適用於舊版本的 ASP.NET Core(取決於此修復程序是否適用於使用過的版本)。
基於以下事實的舊版本解決方法:您始終可以通過.UseConfiguration
方法直接設置主機設置:
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
請注意,相同的想法可用於從任何其他配置源讀取設置值,例如配置文件。
試試下面的,它對我有用。
設置 ASPNETCORE_SERVER.URLS=http://0.0.0.0:5000/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.