如何解决具有身份的应用程序在 Ubuntu 服务器 20.04LTS 上启动时崩溃
在服务器上部署我的 MVC Web 应用程序时,应用程序崩溃。 它在我的本地 Visual Studio 上运行良好,但在我的 Ubuntu 20.04 LTS 上启动时崩溃。
错误是它在我添加身份模块之前启动时没有启动...... 须藤 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://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0#configure-nginx
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。