简体   繁体   English

在启动时在Linux下运行ASP.NET Core应用程序

[英]run ASP.NET Core app under Linux on startup

I would like to run my ASP.NET Core solution under linux with the result it runs on startup. 我想在linux下运行我的ASP.NET核心解决方案,并在启动时运行它的结果。

From Microsoft docs , there are 2 ways: Apache and Nginx . 从Microsoft docs ,有两种方式: ApacheNginx

Both approaches involve proxy pass , eg 两种方法都涉及代理传递 ,例如

Apache: 阿帕奇:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ....

Nginx: Nginx的:

server {
    listen        80;
    server_name   example.com *.example.com;
    location / {
        proxy_pass         http://localhost:5000;
        ...

Since Apache or Nginx only acts as proxy - do I get it right that I have to manually start the dotnet app ? 由于Apache或Nginx仅作为代理 - 我是否正确地说我必须手动启动dotnet应用程序

I can't see the bit in the documentation where something could trigger dotnet run command against my WebApi project. 我无法在文档中看到某些东西可以触发针对我的WebApi项目的dotnet run命令。

Obviously, Apache or Nginx wouldn't handle triggering dotnet app - unless I've missed something. 显然,Apache或Nginx不会处理触发的dotnet应用程序 - 除非我错过了什么。

Is there a way to automatically start the app on OS startup ? 有没有办法在OS启动时自动启动应用程序

This section in docs describes, how to create a service file to automatically start your Asp.Net Core app. 文档中的这一部分介绍了如何创建服务文件以自动启动Asp.Net Core应用程序。

Create the service definition file: 创建服务定义文件:

 sudo nano /etc/systemd/system/kestrel-hellomvc.service 

The following is an example service file for the app: 以下是该应用的示例服务文件:

 [Unit] Description=Example .NET Web API App running on Ubuntu [Service] WorkingDirectory=/var/aspnetcore/hellomvc ExecStart=/usr/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 SyslogIdentifier=dotnet-example User=www-data Environment=ASPNETCORE_ENVIRONMENT=Development [Install] WantedBy=multi-user.target 

Save the file and enable the service. 保存文件并启用该服务。

 systemctl enable kestrel-hellomvc.service 

Start the service and verify that it's running. 启动该服务并验证它是否正在运行。

 systemctl start kestrel-hellomvc.service systemctl status kestrel-hellomvc.service 

You need to set WorkingDirectory - path to folder with your app and ExecStart - with path to your app dll. 您需要设置WorkingDirectory - 使用您的应用程序和ExecStart文件夹路径 - 以及您的应用程序DLL的路径。 By default this is enough. 默认情况下这就足够了。

From now, your app will automatically start on OS startup and will try to restart after crashes . 从现在开始,您的应用程序将在操作系统启动自动启动 ,并将在崩溃后尝试重新启动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Core 3:无法在 linux 上运行 - ASP.NET Core 3: cannot run on linux 有没有办法检查和清理 Docker 化并在 Linux 下运行的 ASP.NET Core 应用程序的证书吊销列表缓存? - Is there a way to check and clean Certificate Revocation List cache for ASP.NET Core application that is dockerized and run under the Linux? 从单声道下的asp.net mvc app安全地运行linux命令行应用程序 - securely run linux command line app from asp.net mvc app under mono 任何ASP.net应用程序(或大多数)可以使用Mono在Linux下运行吗? - can any ASP.net app (or most of them) be made to run under Linux using Mono? 在Linux或Mac上运行asp.net核心控制台应用程序 - Run asp.net core console application on Linux or Mac arch linux 上的 asp.net core 2.1 无法运行 - asp.net core 2.1 on arch linux does not run 从 ASP.NET Core 3 应用程序执行 Linux Shell 命令 - Exectute a Linux Shell command from ASP.NET Core 3 app 将ASP.NET Core 1.1发布到基于Linux的应用程序服务 - Publish ASP.NET Core 1.1 to a Linux based App Service 当前的RTMed ASP.NET MVC 5项目可以在.NET Core上运行以在Linux上运行吗? - Can current RTMed ASP.NET MVC 5 project run on .NET Core to run in Linux? 如何从 ASP.NET 创建 PID 文件 Linux 下的核心应用 - How to create PID file from ASP.NET Core application under Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM