分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

.net core项目部署到centos7

发布时间:2023-09-06 01:19责任编辑:熊小新关键词:暂无标签

环境说明     

系统:CentOS Linux release 7.2.1511 (Core)

相关工具:xftp

服务器软件:.net core,nginx

准备.net core应用程序

 .NET Core分为两种应用类型:Portable applications(便携应用)          Self-contained application(自宿主应用)

我们选择便携应用,这样发布的项目会小一点,也是微软推荐的发布方式。




  • 确保这份发布应用可以在windows上运行,以减少后续的问题。

 

服务器安装CentOS7

这个不多说了,网上好多教程。

服务器安装.net sdk for .net core

sudo yum install libunwind libicu(安装libicu依赖)curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131(下载sdk压缩包,不一定非要用这个,可以去官网找最新的链接) sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet(解压缩)sudo ln -s /opt/dotnet/dotnet /usr/local/bin(创建链接)

输入 dotnet –info 来查看是否安装成功

如果可以执行则表明.NET Core SDK安装成功

部署.net core应用程序到服务器

使用Xftp上传到服务器,需要注意一点,配置xftp时,协议选择sftp,不要选ftp,否则会出现连不上服务器的情况。

项目上传至服务 home/WebApp

检查项目是否能够运行

命令:dotnet /home/WebApp/WebApp.dll

  

可以看到端口号是5000:Now listening on: http://localhost:5000

安装Nginx

curl -o ?nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmrpm -ivh nginx.rpmyum install nginx

输入:systemctl start nginx 来启动nginx。

输入:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。

配置Nginx对Asp .Net Core的转发

修改 /etc/nginx/conf.d/default.conf 文件。

将文本内容替换为上图:

server { ???listen ??????80; ???server_name ?localhost; ???#charset koi8-r; ???#access_log ?/var/log/nginx/host.access.log ?main; ???location / { ???????root ??/usr/share/nginx/html; ???????index ?index.html index.htm; ???????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; ???} ???#error_page ?404 ?????????????/404.html; ???# redirect server error pages to the static page /50x.html ???# ???error_page ??500 502 503 504 ?/50x.html; ???location = /50x.html { ???????root ??/usr/share/nginx/html; ???}}

:wq 覆盖保存。

执行:nginx –s reload 使其即时生效

 感谢博客园的大牛园友的无私奉献!!

参考:http://www.cnblogs.com/ants/p/5732337.html

.net core项目部署到centos7

原文地址:http://www.cnblogs.com/nowar/p/7698769.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved