How to deploy ASP.NET Core application?

Posted December 2, 2016 18.2k views
NginxMongoDBUbuntu 16.04

I created a sample ASP.NET Core Web API application with MondoDB following these tutorials

  1. Using MongoDB .NET Driver with .NET Core WebAPI
  2. Publish to a Linux Production Environment
  3. Publishing an ASP.NET Core website to a cheap Linux VM host

Excited about the prospect of deploying an ASP.NET application in a Linux environment, i got the $5 plan and installed Ubuntu.

I have been successful in running the application and nginx locally with the application listening @ port 5000. However, i’m unable to access my application from outside. I’m getting the ‘502 bad gateway’ error.

Could anyone with experience on the above stack help me out? Thanks for your time.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

A 502 error usually means one of two things.

1.) Your application is not listening locally as expected on http://localhost:5123

Test this by using wget/curl or telnet to open the service from from your ssh session on the server and make sure it responds. If it’s not, try restarting supervisor.

2.) Your nginx configuration is not correct.

Share your nginx configuration here and we can take a look at it.

  • Thanks @ryanpq for answering.

    Sorry, since i’m not familiar with linux environment/ecosystem, i don’t understand your first point. Like i said, i got the server just to see how ASP.NET Core works with Linux hosting. Whatever i’ve done so far are from following tutorials. Btw i’m using MobaXTerm to access the server with only username/password. I haven’t set up SSH for now, will do so once i get the hang of things.

    As for the second point, below is my nginx configuration (default):

    server {
        listen 80;
        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;
    • You should be able to execute commands with MobaXTerm on server, you don’t have to set up anything special.

      Nginx config looks good. You can test it to be sure (if you’re able to execute commands on server) with:

      • sudo nginx -t

      I would check what Ryan said in first step. CURL or wget the http://localhost:5000.
      When you execute:

      curl http://localhost:5000

      On your server, you need to see positive answer (it should be page source).
      You can do the same with wget.

      In case you see error, check if your app is running. Make sure you have it on that port.