nginx部署.net core站点的方法
步骤
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
相关推荐
yserver 2020-08-15
张立军的架构之路 2020-09-28
yongzhang 2020-07-19
nginxs 2020-11-14
Guanjs0 2020-11-13
小木兮子 2020-11-11
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09