1.先安装好nodejs的版本

我centos7版本,最后发现支持nodejs-v16.20版本

[sytyuser1@syit-dev-linux-01 node]$ pwd
/usr/local/node

在 /usr/local/node   目录下载wget https://nodejs.org/dist/latest-v16.x/node-v16.20.2-linux-x64.tar.gz

解压 tar-zxvf node-v16.20.2-linux-x64.tar.gz

移动到node

[sytyuser1@syit-dev-linux-01 node]$ ll
总用量 33828
drwxr-xr-x 2 sytyuser1 sytyuser1 119 8月 7 14:05 bin
-rw-r--r-- 1 sytyuser1 sytyuser1 720035 8月 9 2023 CHANGELOG.md
drwxr-xr-x 3 sytyuser1 sytyuser1 18 8月 9 2023 include
drwxr-xr-x 3 sytyuser1 sytyuser1 26 8月 9 2023 lib
-rw-r--r-- 1 sytyuser1 sytyuser1 92799 8月 9 2023 LICENSE
drwxr-xr-x 2 sytyuser1 sytyuser1 6 8月 7 13:20 node-v16.20.2-linux-x64
-rw-rw-r-- 1 sytyuser1 sytyuser1 33784208 8月 9 2023 node-v16.20.2-linux-x64.tar.gz
-rw-r--r-- 1 sytyuser1 sytyuser1 35345 8月 9 2023 README.md
drwxr-xr-x 5 sytyuser1 sytyuser1 45 8月 9 2023 share

1
<br>

  

2.打包项目

1
2
3
yarn build
# or
npm run build
会得到

 

3.安装pm2

1
npm install -g pm2

  

 用pm2 -v查看版本,查看是否成功

1
2
[sytyuser1@syit-dev-linux-01 test]$ pm2 -v
5.4.2

  

4.配置pm2 

在.output同目录创建touch pm2.config.js

1
2
3
4
5
6
7
8
9
10
11
module.exports = {
apps: [
{
  name: 'junjie',
  port: '3005',
  exec_mode: 'cluster',
  instances: 'max',
  script: './.output/server/index.mjs'
}
]
}

  

5.编写SSR对应的nginx脚本

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
listen 80;
    server_name nacos.firefly;
    # 在server块中设置client_max_body_size
    client_max_body_size 10M;
    #常规写法
    #location / {
    #   root   /usr/share/nginx/html/tieba-app;
    #   index  index.html index.htm;
    #   try_files $uri $uri/ /index.html;
   # }
 
   
    location /app-api {
        proxy_pass http://app;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
 
        # 添加以下指令以处理静态资源
        proxy_set_header Accept-Encoding "";
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    
   location / {
        proxy_pass http://localhost:3005/;
    }

 6.写一个启动脚本start.sh,目录为

1
2
3
4
5
6
7
8
9
10
[sytyuser1@syit-dev-linux-01 tieba-app]$ pwd
/usr/share/nginx/html/tieba-app
[sytyuser1@syit-dev-linux-01 tieba-app]$ ll -a
总用量 3000
drwxrwxrwx 3 root      root           77 8月   7 14:09 .
drwxr-xr-x 6 root      root          223 7月  30 11:33 ..
drwxrwxr-x 4 sytyuser1 sytyuser1      52 8月   7 13:58 .output
-rw-rw-r-- 1 sytyuser1 sytyuser1 3063634 8月   7 13:56 .output.zip
-rw-rw-r-- 1 sytyuser1 sytyuser1     193 8月   7 13:54 pm2.config.js
-rwxrwxrwx 1 sytyuser1 sytyuser1      25 8月   7 14:09 start.sh内容

内容为:

1
pm2 start pm2.config.js

 

访问http://nacos.firefly即可成功


借鉴大佬的文章:
https://www.yinchunyu.com/nuxt3/deploy.html

posted on   我是坏男孩  阅读(250)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
< 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
点击右上角即可分享
微信分享提示