.net6 core web项目发布部署到Linux,以守护进程服务的形式部署启动,nginx实现转发

一、发布项目

1、以文件夹形式
2、目标运行时选对应的平台(Linux-x64)
3、文件夹选项:在发布前删除所有现有文件
在这里插入图片描述
在这里插入图片描述

二、部署项目(安装.net6环境:参考Linux安装 dotnet sdk 6.0

(1)使用Xftp将项目发布文件上传到Linux服务器上的指定目录,如:/var/www
在这里插入图片描述
(2)为应用程序分配可执行权限

# chmod +x /var/www/chinahorn.mail.web.core/Chinahorn.Mail.Web

在这里插入图片描述
(3)新建chinahorn.mail.web.core.service守护进程文件,移动至 /etc/systemd/system/

1、 ExecStart:设置项目路径、端口
2、使用systemctl命令重新加载新的配置文件 # systemctl daemon-reload

[Unit]
Description=Running ASP.NET Core on Ubuntu 20.04 Webserver APACHE

[Service]
Type=simple
ExecStart=/root/dotnet/dotnet /var/www/chinahorn.mail.web.core/Chinahorn.Mail.Web.dll --urls=http://localhost:5003
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=chinahornmailweb
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

在这里插入图片描述
(4)重新加载配置文件,启动服务

1、使用systemctl命令重新加载新的配置文件
# systemctl daemon-reload
2、启动服务
# systemctl start chinahorn.mail.web.core
3、停止服务
# systemctl stop chinahorn.mail.web.core
4、重启服务
# systemctl restart chinahorn.mail.web.core
5、重新查看服务状态
# systemctl status chinahorn.mail.web.core
6、设置服务开机自启
# systemctl enable chinahorn.mail.web.core
7、禁用开机自启
# systemctl disable chinahorn.mail.web.core

(5)nginx实现转发

1、安装nginx
2、配置转发,location处理静态文件

 server {
        listen 80;
        listen  [::]:80;
        server_name chinahorn.mail.web.core;
        location / {
			proxy_pass http://localhost:5003/;
			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-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
		location /Content{
			alias '/var/www/chinahorn.mail.web.core/wwwroot/Content'; 
		}
    }
三、浏览器打开输入Linux ip,看成就

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

下一秒_待续

如有帮到您,给个赞赏(^.^)

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值