1、环境说明:
服务器系统:CentOS 7.4 64位
相关工具:Xshel、Xftp
.net Core版本:3.1
VS版本:2019
服务器软件软件:.netcore、nginx、
2.环境安装.NET Core SDK
命令一:sudo yum update
命令二:sudo yum install libunwind libicu
命令三:sudo yum install dotnet-sdk-3.1.0
使用命令 dotnet --info 查看是否安装成功
通过xftp,将发布好的文件上传至服务器
dotnet xxxxx.dll 查看是否正常启动
2.安装Nginx
命令一:curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
命令二:rpm -ivh nginx.rpm
命令三: yum install nginx
输入:systemctl start nginx 来启动nginx。
输入:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。
修改 /etc/nginx/conf.d/default.conf 文件。
server {
listen 80;
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;
}
}
执行:sudo nginx -s reload 使其即时生效
3.添加系统守护进程
sudo /etc/systemd/system/kestrel-test.service
增加内容:
[Unit]
Description=Example .NET Web App running on centos
[Service]
WorkingDirectory=/root/netCoreTest
ExecStart=/usr/bin/dotnet /root/netCoreTest/WebApplication1.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
启用服务:
systemctl enable kestrel-test.service 启用
systemctl start kestrel-test.service 启动
systemctl status kestrel-test.service 运行状态
sudo journalctl -fu kestrel-test.service 查看日志