Centos8 下部署 ASP.net Core 程序
Posted 非淡泊无以明志,非宁静无以致远
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos8 下部署 ASP.net Core 程序相关的知识,希望对你有一定的参考价值。
1、安装需要的SDK包,如果程序包含3.1版本,需要安装3.1的SDK。
sudo dnf install dotnet-sdk-5.0
dotnet --version
dotnet --list-runtimes
2、net core程序中带有图片验证码需要事先安装GDI的图形库
https://www.mono-project.com/download/stable/#download-lin-centos
1、Add the Mono repository to your system
CentOS/RHEL 8 (x86_64)
rpmkeys --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
su -c \'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo\'
CentOS/RHEL 7 (x86_64)
rpmkeys --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
su -c \'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo\'
CentOS/RHEL 6 (x86_64, i686)
rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
su -c \'curl https://download.mono-project.com/repo/centos6-stable.repo | tee /etc/yum.repos.d/mono-centos6-stable.repo\'
2、Install Mono
dnf install mono-devel
使用 Nginx 在 Linux 上托管 ASP.NET Core
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-6.0
yum install nginx -y systemctl status nginx systemctl enable --now nginx systemctl start nginx
server { listen 80; server_name example.com *.example.com; location / { proxy_pass http://127.0.0.1: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; } }
把启动命令写成服务
/etc/systemd/system/Core.service
[Unit] Description="Core.Service" [Service] Type=simple GuessMainPID=true WorkingDirectory=/www/web/mng StandardOutput=journal StandardError=journal ExecStart=/usr/lib64/dotnet/dotnet /www/web/mng/clyg_tmc_manage.dll --urls="http://*:5000" Restart=always [Install] WantedBy=multi-user.target
官方给的服务配置文件,供参才考。试了多次都不能启动。
sudo nano /etc/systemd/system/kestrel-helloapp.service
[Unit] Description=Example .NET Web API App running on Ubuntu [Service] WorkingDirectory=/var/www/helloapp ExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-example User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
sudo systemctl enable kestrel-helloapp.service
sudo systemctl start kestrel-helloapp.service
sudo systemctl status kestrel-helloapp.service
参考链接
https://huchengv5.github.io/post/%E5%A6%82%E4%BD%95%E5%B0%86Asp.net-Core%E7%AB%99%E7%82%B9%E9%83%A8%E7%BD%B2%E5%88%B0CentOS.html
以上是关于Centos8 下部署 ASP.net Core 程序的主要内容,如果未能解决你的问题,请参考以下文章
在Linux环境下使用Apache部署ASP.NET Core