步骤
aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001.
把发布出来的文件全部丢掉 /var/www/JuXiangTou 里面去。可以用scp命令或者winscp客户端
- centos 7.x
- aspnet core 的运行环境,不需要装sdk,一般sdk里面是包含runtime的
yum install libunwind libicu
yum install aspnetcore-runtime-2.1 nginx,一个反向代理服务,把过来的http请求转发给实际的aspnetcore处理sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx 装好nginx要配置端口之类的。cd /etc/nginx/ nginx.conf是默认的配置文件,基本不用动。cd conf.d
vim kestrel-juxiangtou.conf 下面主要就是两个端口号的需要改一下,其他都可以不用改动。server {
listen 8001;
location / {
proxy_pass http://localhost:5001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
} 保存退出
验证一下配置,然后重新载入sudo nginx -t
sudo nginx -s reload 防火墙firewall-cmd。不一定装过,要看环境。systemctl status firewalld
firewall-cmd --zone=public --add-port=8001/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld.service 建一个服务,用于维护dotnetcore的程序进程cd /etc/systemd/system
vim kestrel-juxiangtou.service
[Unit]
Description=JuXiangTou
[Service]
WorkingDirectory=/var/www/JuXiangTou
ExecStart=/usr/bin/dotnet /var/www/JuXiangTou/Site.WebApi.dll
Restart=always
RestartSec=10
SyslogIdentifier=JuXiangTou
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target 保存退出systemctl restart kestrel-juxiangtou.service 重启一下服务。
配置一下阿里云的网络安全组里面的端口
参考资料
http://www.projectcodify.com/hosting-aspnet-core-on-linux-using-nginx
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.cnblogs.com/sheldon-lou/p/9277085.html
|