直接使用vs2019编译发布后,通过ftp上传到centos的 /www/ 目录下,不再赘述。
1 2 3 4 5 6 |
#注册 Microsoft 密钥。注册产品存储库。安装必需的依赖项。 sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm #安装 .NET Core 运行时 sudo yum install aspnetcore-runtime-3.1 |
1 |
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm |
1 |
$ sudo yum -y install nginx |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 卸载 nginx $ sudo yum remove nginx # 设置开机启动 $ sudo systemctl enable nginx # 启动 nginx 服务 $ sudo service nginx start # 停止 nginx 服务 $ sudo service nginx stop # 重启 nginx 服务 $ sudo service nginx restart # 重新加载配置,一般是在修改过 nginx 配置文件时使用。 $ sudo service nginx reload #查看nginx版本 $ nginx -v |
在 /etc/nginx/ 目录下新建AspnetCoreDemo.conf,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
server { listen 80; server_name 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; } } |
1 2 3 4 |
# 验证配置文件的语法 $ sudo nginx -t # 强制 Nginx 选取更改。 $ sudo nginx -s reload |
路径 /etc/systemd/system/AspnetCoreDemo.service 新建文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[Unit] Description=AspnetCoreDemo running on Centos [Service] WorkingDirectory=/www ExecStart=/usr/bin/dotnet /www/AspnetCoreDemo.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=AspnetCoreDemo #User=www-data #Production:生产环境 Development:开发环境 Environment=ASPNETCORE_ENVIRONMENT=Development Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target |
1 2 3 4 5 6 7 8 9 10 |
#启用 systemctl enable AspnetCoreDemo.service #启动 systemctl start AspnetCoreDemo.service #状态 systemctl status AspnetCoreDemo.service #重启 systemctl restart AspnetCoreDemo.service #关闭 systemctl stop AspnetCoreDemo.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
1、开放端口 firewall-cmd --zone=public --add-port=5000/tcp --permanent # 开放5000端口 firewall-cmd --zone=public --remove-port=5000/tcp --permanent #关闭5000端口 firewall-cmd --reload # 配置立即生效 2、查看防火墙所有开放的端口 firewall-cmd --zone=public --list-ports 3.、关闭防火墙 如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估 systemctl stop firewalld.service 4、查看防火墙状态 firewall-cmd --state |
from:https://www.cnblogs.com/wxb8/p/12359521.html