skip to Main Content

I’m trying to run ASP.Net Core 5.0 on Ubuntu 20.04 server and I’m getting a white screen after everything is running. Network tab in FireFox is giving the HTTP/1.1 500 Internal Server Error, so Ive been searching the internet for the last two weeks trying to figure this out before coming to SO.

Here is how I have everything configured as of right now.

I created a Ubuntu 20.04 LTS x64 droplet on Digital Ocean and installed Nginx.

Here are the steps I took to install Nginx and get it running.

Installed all the needed Microsoft packages like the SDK and Runtime

Everything was up and running I could see the normal Nginx Welcome screen. Created a server block and added an Index.html file and could see that just fine as well.

Then I created a directory like so sudo mkdir -p /var/www/myDomainName
also giving my self the needed permissions

cloned my repo from GitHub to the newly created dir which has the needed Forwarding Headers middleware changes to the startup.cs as stated in the Microsoft docs.

I run the dotnet build command and get the following.

/var/www/myDomain/src/Presentation/CTA.Web$ dotnet build
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.Views.dll

Build succeeded.
  0 Warning(s)
  0 Error(s)

Time Elapsed 00:00:02.25

Then I run the dotnet publish command and get the following

/var/www/myDomain/src/Presentation/CTA.Web$ dotnet publish
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
All projects are up-to-date for restore.
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/CTA.Web.Views.dll
CTA.Web -> /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/

Then I configure the server by creating and editing my server block which shows this:

server {

    server_name myDomain.com www.myDomain.com;

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myDomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myDomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = www.myDomain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = myDomain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


   listen 80 ;
   listen [::]:80 ;
#server_name myDomain.com www.myDomain.com;
return 404; # managed by Certbot

I run the sudo nginx -s reload command as well.

in the /etc/systemd/system I created a myDomain.service file and added the following.

[Unit]
Description=Archery app

[Service]
WorkingDirectory=/var/www/myDomain
ExecStart=/usr/bin/dotnet /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/CTA.Web.dll
Restart=always
RestartSec=10
SyslogIdentifier=archery
User=myUsername
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

I run the 3 commands

sudo systemctl enable myDomain.service    
sudo systemctl start myDomain.service    
sudo systemctl status myDomain.service

and here is what I get for the status

myDomain.service - Archery app
 Loaded: loaded (/etc/systemd/system/myDomain.service; enabled; vendor preset: enabled)
 Active: active (running) since Sun 2021-12-12 02:38:49 UTC; 3 days ago
 Main PID: 28005 (dotnet)
 Tasks: 11 (limit: 1136)
 Memory: 51.7M
 CGroup: /system.slice/myDomain.service
         └─28005 /usr/bin/dotnet /var/www/myDomain/src/Presentation/CTA.Web/bin/Debug/net5.0/publish/CTA.Web.dll

 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, >Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.HandleException(HttpContext context, ExceptionDispatchInfo edi)
 Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, >Dec 15 02:28:27 eComArchery archery[28005]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
 Dec 15 02:28:27 eComArchery archery[28005]: info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
 Dec 15 02:28:27 eComArchery archery[28005]: Request finished HTTP/1.1 GET http://example.com/ - - - 500 0 - 32.0811ms

If there is anythign else anyone would like to see let me know.

2

Answers


  1. Note that you may have a correct server configuration as internal server errors may come from other reasons.

    You have to see what happens in the background by enabling logs. For this, see the How i can logging messages from asp.net core application in specific file on linux? and Logging in .NET Core and ASP.NET Core to know how to enable it on linux.
    And then you can find the main problems.

    Login or Signup to reply.
  2. You have an internal server error, It’s not an error from the server config. The application return a 500.
    In terminal you can write

    journalctl -u [YourServiceName].service --since '2021-MM-DD hh:mm:ss'

    to get the lasts errors of your app. Fix it, re-deploy.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search