deploy an API on a linux server with NGINX

Marnelle M'BENGUET 20 Reputation points
2023-09-11T09:37:28.3633333+00:00

Hello, I am trying to deploy an ASP.NET CORE API on a linux server with nginx, I have already managed the publishing stage in visual studio and I have placed the published folders in var/www

Capture d'écran 2023-09-11 110757

then i configured the etc/nginx/site_available/default file like this

Capture d'écran 2023-09-11 111351

then i created a kestrel of my project in etc/systemd/system

[Unit] Description=Example .NET Web API App running on Linux [Service] WorkingDirectory=/var/www/helloapp ExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-example User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install]

then i activated it without problem with the command "sudo systemctl enable kestrel-APIDossiers"

i start it with sudo systemctl start kestrel-APIDossiers

but i have the error "site innaccessible" anyone has an idea what it is?


Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
726 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,412 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,661 questions
Microsoft Intune Linux
Microsoft Intune Linux
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Linux: A family of open-source Unix-like operating systems.
46 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,811 Reputation points
    2023-09-11T15:48:03.9033333+00:00

    first check the service is ok. if the code is using host headers use postman or curl and set the headers.

    [http://127.0.0.1:5000;]

    you can also check the system log to be sure you have the correct port.


  2. Sreeju Nair 12,176 Reputation points
    2023-09-12T08:44:29.0566667+00:00

    I recommend you to view the following article

    https://weblogs.asp.net/sreejukg/step-by-step-guide-to-deploying-an-asp-net-core-app-to-ubuntu-vm-in-azure-using-nginx

    I have written step by step guide to publish .net application to Ubuntu and NGINX. Try to follow the steps. The commands are published to Github

    https://github.com/sreejukg/DeployASP.NetCoreToLinux/blob/main/asp.netcorelinuxdeploymentscrpts

    Hope this helps