这篇文章主要介绍了nginx部署.netcore站点的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
步骤
aspnetcore程序端口号5001,实际外部端口号8001,相当于把8001收到的请求转发给5001.
把发布出来的文件全部丢掉/var/www/JuXiangTou里面去。可以用scp命令或者winscp客户端
centos7.xaspnetcore的运行环境,不需要装sdk,一般sdk里面是包含runtime的
yuminstalllibunwindlibicuyuminstallaspnetcore-runtime-2.1
nginx,一个反向代理服务,把过来的http请求转发给实际的aspnetcore处理
sudoyuminstallepel-releasesudoyuminstallnginxsudosystemctlstartnginxsudosystemctlenablenginx
装好nginx要配置端口之类的。
cd/etc/nginx/
nginx.conf是默认的配置文件,基本不用动。
cdconf.dvimkestrel-juxiangtou.conf
下面主要就是两个端口号的需要改一下,其他都可以不用改动。
server{listen8001;location/{proxy_passhttp://localhost:5001;proxy_http_version1.1;proxy_set_headerUpgrade h t t p u p g r a d e ; p r o x y s e t h e a d e r C o n n e c t i o n k e e p − a l i v e ; p r o x y s e t h e a d e r H o s t http_upgrade;proxy_set_headerConnectionkeep-alive;proxy_set_headerHost httpupgrade;proxysetheaderConnectionkeep−alive;proxysetheaderHosthttp_host;proxy_cache_bypass$http_upgrade;}}
保存退出
验证一下配置,然后重新载入
sudonginx-tsudonginx-sreload
防火墙firewall-cmd。不一定装过,要看环境。
systemctlstatusfirewalldfirewall-cmd–zone=public–add-port=8001/tcp–permanentfirewall-cmd–reloadsystemctlrestartfirewalld.service
建一个服务,用于维护dotnetcore的程序进程
cd/etc/systemd/systemvimkestrel-juxiangtou.service
[Unit]Description=JuXiangTou[Service]WorkingDirectory=/var/www/JuXiangTouExecStart=/usr/bin/dotnet/var/www/JuXiangTou/Site.WebApi.dllRestart=alwaysRestartSec=10SyslogIdentifier=JuXiangTouUser=rootEnvironment=ASPNETCORE_ENVIRONMENT=流量交易Production[Install]WantedBy=multi-user.target
保存退出
systemctlrestartkestrel-juxiangtou.service
重启一下服务。
配置一下阿里云的网络安全组里面的端口