随笔 - 165, 文章 - 0, 评论 - 18, 阅读 - 22万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

net core 6 部署到ubuntu

Posted on   火冰·瓶  阅读(105)  评论(0编辑  收藏  举报

一、安装dotnet SDK

 1.更新源

1
sudo apt-get update;

2.启用 Microsoft PPA

1
2
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

3.安装.NET Core SDK

1
2
3
sudo apt install apt-transport-https
sudo apt update
sudo apt install dotnet-sdk-6.0

4.检查版本确认安装结果

1
dotnet --version

5.将项目发布,并上传到ubantu

6.直接运行

1
2
3
4
5
dotnet xxx.dll   #默认端口 5000
dotnet xxx.dll --urls=http://*:5051  #指定端口
 
#启动站点,自定义端口号,运行环境
dotnet Core50Test.dll --urls="http://*:8081;http://*:8082" --environment=Development<br><br><br>

7.也可以在appsettings.json中指定端口

1
2
3
4
5
6
7
8
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:50050"
      }
    }
  }
}

  

  

 

 

二、安装并配置pm2

1.更新源

1
sudo apt-get update

2.安装 NodeJS

1
sudo apt install nodejs

3.安装npm

1
sudo apt install npm

4.安裝 PM2

1
npm install pm2 -g

5.设置pm2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//生成开机启动 pm2 服务的配置文件
pm2 startup
   
//保存服务
pm2 save
   
//启动进程/应用
pm2 start bin/www
pm2 start app.js
pm2 start test.sh
pm2 start "dotnet TestUbuntu.dll --urls http://*:8090" --name test     //设置启动net core网址、设置端口号为8090,并设置pm2进程名称为test
   
//启动进程/应用并命名进程
pm2 start app.js --name wb123
   
//结束进程/应用
pm2 stop www
   
//结束所有进程/应用
pm2 stop all
   
//删除进程/应用
pm2 delete www
   
//删除所有进程/应用
pm2 delete all
   
//列出所有进程/应用
pm2 list
   
//查看某个进程/应用具体情况
pm2 describe www
   
//查看进程/应用的资源消耗情况
pm2 monit
   
//查看pm2的日志
pm2 logs
   
//若要查看某个进程/应用的日志,使用
pm2 logs www
   
//重新启动进程/应用
pm2 restart www
pm2 restart [进程名] | [进程id]  // 重启效果 短时间内进程无效
pm2 reload [进程名] | [进程id] // 重载效果 会保持进程在线
 
//内存达到30M时,重启进程
pm2 start test.sh --max-memory-restart 300M   
 
//重新启动所有进程/应用
pm2 restart all
 
//查看某一个进程的详细信息
pm2 show [进程名] | [进程id]

  

三、安装并配置nginx

1
apt-get install nginx

如果需要使用ssl,则需要编译后安装,详见:https://www.cnblogs.com/fireicesion/p/17338966.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
user  root;     #建议修改,否则容易出现静态文件禁止访问
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
 
##############################################################################
    server {
    listen 80;
    server_name t1.xxxx.net;
    location / {
        proxy_pass http://localhost:50000;   #反向代理
        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;
        }
    }
     
##############################################################################
 
 
    server{
        listen 80;
        server_name bigdata.xxxx.net;
        rewrite ^(.*)$ https://${server_name}$1 permanent; #设置http自动转发https
    }
    server {
    listen 443 ssl;
    server_name bigdata.xxxx.net;
    ssl_certificate      /root/ssl/xxxx.pem;     #证书路径
    ssl_certificate_key  /root/ssl/xxxx.key;     #证书路径
 
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
 
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;
    location / {
        proxy_pass http://localhost:50001;   #反向代理
        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;
        }
    }
 
#################################################################################
 
 
    server{
        listen 80;
        server_name www.aabbcc.com aabbcc.com;
        rewrite ^(.*)$ https://${server_name}$1 permanent; #设置http自动转发https
    }
    server {
        listen 443 ssl;
        server_name  www.aabbcc.com;
        ssl_certificate      /root/ssl/aaa/pem.pem;
        ssl_certificate_key  /root/ssl/aaa/key.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        root   /root/wwwroot/projectname;    #静态文件路径
        index  index.html index.htm;         #静态文件首页
    }
 
}

  

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-04-20 Linq to SQL各种参考
点击右上角即可分享
微信分享提示