带有标识的应用程序在Ubuntu服务器20.04LTS上启动时崩溃



在服务器上部署MVC web应用程序时发生应用程序崩溃。它在我当地的visual studio上运行良好,但在我的Ubuntu 20.04 LTS上启动时崩溃。

错误是它在我添加身份模块之前启动时没有启动。。。sudo systemctl停止myapp.service

● myapp .service - myapp app
Loaded: loaded (/etc/systemd/system/myapp .service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2021-01-11 11:54:21 UTC; 4s ago
Process: 17943 ExecStart=/usr/bin/dotnet /var/www/myapp .be/net5.0/myapp .be.dll (code=exited, status=1/FAILURE)

主PID:17943(代码=已退出,状态=1/故障(

我怀疑身份管理器崩溃了。当它在我的visual studio windows开发环境中托管时运行良好最烦人的是它没有崩溃,甚至没有启动,没有显示错误。。。

我的startup.cs文件

using mysite.com.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.OAuth;
namespace mysite.com
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddGoogle(options =>
{
//clean this latter know how to implement user secrets.json
options.ClientId = "xxxxxx.apps.googleusercontent.com";
options.ClientSecret = "xxxxxx";
})
.AddFacebook(facebookOptions =>
{
facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
})
;
string mySqlConnectionStr = Configuration.GetConnectionString("DefaultConnection");

services.AddDbContextPool<ApplicationDbContext>(options => options.UseMySql(mySqlConnectionStr, ServerVersion.AutoDetect(mySqlConnectionStr)));
services.AddControllers();
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();

}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
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();
});

}
}
}

更新1:仍在调查,但从我在github等上看到的情况来看…身份可能在Linux上被破坏。。。所以我切换到Windows服务器,一切正常。。。

您可以在终端中使用以下命令运行您的项目

dotnet run

如果您的项目已发布,您可以在终端中使用以下命令

dotnet YourProject.dll

我认为你可以在Linux服务器中为你的.net核心项目使用Nginx反向代理

server {
listen        80;
server_name   example.com *.example.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;
}
}

有关Host ASP.NET Core on Linux with Nginx的更多信息:https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0#配置nginx

最新更新