0
votes

I followed the brilliant article by Scott Hanselman http://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx

I got the supervisor started, but when I browse to my Digitial Ocean Droplet I just get a 502 Bad Gateway.

Any ideas?

anton@ubuntu-512mb-lon1-01:/var/dotnettest$ sudo tail -f /var/log/dotnettest.out.log

Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. warn: Microsoft.Extensions.DependencyInjection.DataProtectionServices[59] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50] Using an in-memory repository. Keys will not be persisted to storage. Hosting environment: Production Content root path: /var/dotnettest Now listening on: http://localhost:5000

anton@ubuntu-512mb-lon1-01:/var/dotnettest$ sudo tail -f /var/log/supervisor/supervisord.log

> 2017-02-15 08:11:58,737 INFO waiting for dotnettest to die 2017-02-15
> 08:11:58,782 WARN received SIGTERM indicating exit request 2017-02-15
> 08:11:58,815 INFO stopped: dotnettest (exit status 0) 2017-02-15
> 08:12:09,996 CRIT Supervisor running as root (no user in config file)
> 2017-02-15 08:12:09,996 WARN Included extra file
> "/etc/supervisor/conf.d/dotnettest.conf" during parsing 2017-02-15
> 08:12:10,006 INFO RPC interface 'supervisor' initialized 2017-02-15
> 08:12:10,007 CRIT Server 'unix_http_server' running without any HTTP
> authentication checking 2017-02-15 08:12:10,007 INFO supervisord
> started with pid 13383 2017-02-15 08:12:11,011 INFO spawned:
> 'dotnettest' with pid 13388 2017-02-15 08:12:12,013 INFO success:
> dotnettest entered RUNNING state, process has stayed up for > than 1
> seconds (startsecs)
2

2 Answers

3
votes

Got it working, hope it helps someone else... 4 x Ubuntu images later... :)

Bad Gateway is caused by the Kestrel server not serving on the same Port as what you have Nginx listen on.

First Off, make sure you actually add the .UserConfiguration(config) in the Program.Main

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) //MAKE SURE THIS IS IN
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

Also make sure you added the using Microsoft.Extensions.Configuration; namespace to the Program.cs

Then add your hosting.js file to the route as per Scott's post.

If you now do a dotnet run make sure the app started on the port you specified in the hosting.js file as per Scott post it will be :5123

After you published the app and do the supervisor stop and start make sure that the port is 5123 by running this

sudo tail -f /var/log/dotnettest.out.log

This must be port 5123 and not the default 5000, if it is then you missing the hosting.js file in your published directory, if you followed the post it will be /var/dotnettest

The only other really stupid thing I did was that I published my app under testapp while the supervisor conf was looking for dotnettest.dll and not testapp.dll which will give you a lovely

nginx supervisor terminated by SIGABRT; not expected

error

Thanks to Scott Hanselman, what will be do without these guys... http://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx

Cheers

0
votes

If Anton's remarks still do not work, it might be worth checking if Startup.Configure() is using app.UseHttpsRedirection(); while hosting.json/arguments and Nginx setup are not prepared for that.

In my case, right from the beginning I tried setting up SSL since the Visual Studio template I was using had it enabled by default (SPA with Angular), but after a while it became too hard and decided to leave it for later... just forgot to remove that line form Startup.cs, which caused the app to repeatedly respawn upon failure.

I found that out by looking at the error log with sudo tail -f /var/log/myapp.err.log (or whatever filename you set up in supervisor's config file)