[英]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 ,有两种方式: Apache和Nginx 。
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.