Deploy my webapi dotnet core project to Ubuntu server Configuration with kestrel and proxy via nginx
my code in file Program.cs
public class Program {
public static void Main(string[] args) {
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:5050")
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Created file in /etc/nginx/sites-available/default
and maded symlink to /etc/nginx/sites-enable/default
server {
listen 80;
location / {
proxy_pass http://localhost:5050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
}
my file in /etc/systemd/system/kestrel-project.service
[Unit]
Description=WebApi .NET Core running on Ubuntu
[Service]
WorkingDirectory=/var/aspnetcore/project
ExecStart=/usr/bin/dotnet /var/aspnetcore/project/project.dll
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-project
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
For deploy use this script and it's work until this day
dotnet restore
dotnet build
dotnet publish
cp -r /root/src/project/bin/Debug/netcoreapp2.0/publish/* /var/aspnetcore/project/
cp /root/src/project/bin/Debug/netcoreapp2.0/project.dll /var/aspnetcore/project/
service nginx restart
systemctl daemon-reload
systemctl stop kestrel-project.service
systemctl enable kestrel-project.service
systemctl start kestrel-project.service
systemctl status kestrel-project.service
Now when I launch my webapi on my localhost on pc - webapi work well and answer to my requests, but from server I've got HTTP error 500 and in /var/log/nginx/error.log
I see this
2018/02/11 19:58:04 [alert] 10584#10584: aborting
2018/02/11 20:01:15 [error] 11717#11717: *1 connect() failed (111:Connection refused) while connecting to upstream, client: *.*.*.*, server: , request: "GET /list HTTP/1.1", upstream: "http://127.0.1.1:5050/list", host: "*.*.*.*.*"
Please help me to understand this problem and fix it
Without changes webapi work well a long time but a couple of days ago I began to appear these errors