Hi everyone, I am facing a problem where my existing setup returns 404 error when accessing the webpage:
I am trying to setup working .NET application as a service to be accessed from one of the domains created with HestiaCP.
HestiaCP setup
-
Created User: auris
[ Role: user ][ Package: default ] -
Created Domain for this user xxx.co.uk
[ Redirection: enabled ] [ SSL: enabled/verified ]
[ Nginx: no-php ] [ PHP-FPM: no-php ]
[ Fast CGI: disabled ]
Debian 11 setup
- Installed .Net runtimes and SDKs for .Net 5
- Created a service: kestrel-DigitalNotebook.service
- Added user auris to www-data group
[Unit]
Description = DigitalNotebook framework
[Service]
WorkingDirectory=/home/auris/web/xxx.co.uk/public_html
ExecStart=/bin/dotnet /home/auris/web/xxx.co.uk/public_html/DigitalNotebook.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-5-digital_notebook
User=auris
Group=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
.NET 5 setup
- My Startup File below:
using DigitalNotebookData;
using NotebookServices;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using DigitalNotebookData.Models;
using Microsoft.AspNetCore.HttpOverrides;
namespace DigitalNotebook
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
services.AddControllersWithViews();
services.AddSingleton(Configuration);
services.AddScoped<INotebookEntry, EntryContentService>();
services.AddScoped<INotebooks, NotebookContentService>();
services.AddDbContextPool<NotebookContext>(options => options.UseMySql(Configuration["ConnectionStrings:NotebookDataConnectionMysql"], ServerVersion.AutoDetect(Configuration["ConnectionStrings:NotebookDataConnectionMysql"])));
services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddDefaultUI()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<NotebookContext>();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/Identity/Account/Login";
options.AccessDeniedPath = "/denied";
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
}
}
Service display [ Be aware: xxx and xxx2 are different domain names ]
kestrel-DigitalNotebook.service - DigitalNotebook framework
Loaded: loaded (/etc/systemd/system/kestrel-DigitalNotebook.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-02-05 18:45:16 -09; 10h ago
Main PID: 394696 (dotnet)
Tasks: 15 (limit: 9371)
Memory: 55.9M
CPU: 3.285s
CGroup: /system.slice/kestrel-DigitalNotebook.service
└─394696 /bin/dotnet /home/auris/web/xxx.co.uk/public_html/DigitalNotebook.dll
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: No XML encryptor configured. Key {234200ba-8e94-4c14-a300-e038190d3b7f} may be persisted to storage in unencrypted form.
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: info: Microsoft.Hosting.Lifetime[0]
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: Now listening on: http://localhost:5000
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: info: Microsoft.Hosting.Lifetime[0]
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: Application started. Press Ctrl+C to shut down.
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: info: Microsoft.Hosting.Lifetime[0]
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: Hosting environment: Production
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: info: Microsoft.Hosting.Lifetime[0]
Feb 05 18:45:16 xxx2.co.uk dotnet-5-digital_notebook[394696]: Content root path: /home/auris/web/xxx.co.uk/public_html
So, as a result of all of that, I get 404 when I go to xxx.co.uk. Service is running. I researched and found some topics via google on errors dispalyed @ service display, but that should not be an issue as this setup normally works in Ubuntu with Nginx entry as bellow:
server {
server_name xxx.co.uk www.xxx.co.uk;
root /var/www/auris;
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 80; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxx.co.uk/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxx.co.uk/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
}
And Debian should be on the same strain of Linux as Ubuntu, so this may mean that Nginx setup is incorrect as it is automagically generated every time, even if I decide to change it manually. So, any suggestions are appreciated and let me know if you need more info.