Search code examples
linuxasp.net-corenginxumbraco

Umbraco 9 on Linux Server (Kestrel Service)- Site Dies After Deploying Code Changes


I've gotten an Umbraco 9.0.1 instance up and running on a Linux server (Ubuntu 20.04). I'm using what appears to be the recommended approach of using Nginx as a reverse proxy to a Kestrel service

https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0

The issue I'm having is that any time I do a code update and deploy it to my Linux server, followed by a restart of the kestrel service, the site dies. I get a 502 bad gateway error. Reloading the daemon does nothing. The only thing I've found that seems to work is if I navigate to place in the filesystem where I've deployed the published application and run the command:

dotnet Umbraco.Nine.Linux.dll (Umbraco.Nine.Linux being the name of my project and the corresponding dll the result of the publish)

that command just hangs so I hit ctrl + C to stop it, but that brings the site back up.

Has anyone else experienced anything like this? If not, how are you handling Umbraco code deployments to a Linux server? I should add that if I use the default .net core website from Visual Studio, I don't have this issue. I deploy my code and restart the kestrel service and everything is beautiful, no site outage, changes show up. So maybe there is some Umbraco startup process that's making things die?

I've checked the logs for the kestrel service and they just indicate the service stops/restarts as expected. The logs in Nginx confuse me. They say something like

2021/09/27 15:35:08 [error] 81048#81048: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 184.67.248.194, server: <mysite.com>, request: "GET /umbraco/api/test/another HTTP/1.1", upstream: "http://127.0.0.1:2003/umbraco/api/test/another", ..."

EDIT: I thought I should post some additional details, just in case it helps. For the publishing of the project, I am using Visual Studio built in publishing and choosing File System.

Publish Setup

(Note I've tried the single file publish but I haven't even gotten that to run. I get an error indicating some library the project depends upon will not run in single file publish. Again, this seems Umbraco specific as I can get a default asp.net core site to publish just fine like this. I'm only adding this note in case it's relevant to something just being wrong with Umbraco 9 as we're still very early in the release.)

After that I just zip it up, upload it to the server, unzip it with commands like:

unzip -o website.zip -d <path/to/my/web/app/>

Then

sudo systemctl restart <my.kestrel.service>

That's when browsing the site yields the 502 Bad Gateway I described above. Any help on what I'm doing wrong would be greatly appreciated.


Solution

  • So, I solved this, sort of. I've abandoned the whole kestrel thing and I'm using a docker container to run the asp.net core application. I'm still hosting using nginx as a reverse proxy. The only difference is instead of having a systemd kestrel service listening on the specified port, it's a docker container doing it.

    I posted details here: https://our.umbraco.com/forum/umbraco-9/107189-umbraco-nine-on-linux-server-site-dies-after-deploying-code-changes

    Hopefully it helps someone else out!

    I'm pretty excited because the whole thing is 'script'-able so I managed to automate it in an AWS CodePipeline.