2024-01-15 11:44:36 +08:00
|
|
|
|
# gitlink-ssr版本
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### node版本
|
2024-04-23 16:21:05 +08:00
|
|
|
|
12.x/14.x
|
2024-01-15 11:44:36 +08:00
|
|
|
|
#### ng配置
|
2024-04-23 16:21:05 +08:00
|
|
|
|
后端服务另分配一个端口,不再映射域名
|
|
|
|
|
|
改为前端服务映射域名,并转发到3000
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
|
|
|
|
|
```
|
2024-04-23 16:21:05 +08:00
|
|
|
|
server {
|
2024-04-23 18:38:01 +08:00
|
|
|
|
listen 8080;
|
|
|
|
|
|
server_name testforgeplus.trustie.net;
|
|
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
|
root /home/pdl/forgeplus/public/;
|
|
|
|
|
|
autoindex off;
|
|
|
|
|
|
try_files $uri @backend;
|
|
|
|
|
|
}
|
|
|
|
|
|
location @backend {
|
|
|
|
|
|
proxy_pass http://127.0.0.1:3000;
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
}
|
2024-04-23 16:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 8081;
|
|
|
|
|
|
# server_name testforgeplus.trustie.net;
|
|
|
|
|
|
# return http://$server_name$request_uri;
|
|
|
|
|
|
# rewrite ^(.*)$ https://$host$1 permanent;
|
|
|
|
|
|
...
|
|
|
|
|
|
}
|
2024-01-15 11:44:36 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
#### 部署脚本
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2024-04-23 16:21:05 +08:00
|
|
|
|
#!/bin/bash
|
2024-04-16 09:47:29 +08:00
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
set -x
|
|
|
|
|
|
# Avoid root execution
|
|
|
|
|
|
if [ `id|sed -e s/uid=//g -e s/\(.*//g` -eq 0 ]; then
|
|
|
|
|
|
echo "Execution by root not allowed"
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
cd
|
|
|
|
|
|
|
|
|
|
|
|
#上线分支
|
|
|
|
|
|
Branch=pre_gitlink_ssr
|
|
|
|
|
|
#代码路径
|
|
|
|
|
|
Code_Path=/home/pdl/forgeplus/public/react/forgeplus-react
|
|
|
|
|
|
#Build代码路径
|
|
|
|
|
|
Build_Path=/home/pdl/forgeplus/public/react
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
cd $Code_Path
|
|
|
|
|
|
pwd
|
|
|
|
|
|
git checkout $Branch
|
|
|
|
|
|
git pull
|
|
|
|
|
|
|
|
|
|
|
|
# 分别打静态包与node服务包
|
|
|
|
|
|
npm install
|
2024-01-15 11:44:36 +08:00
|
|
|
|
npm run build
|
|
|
|
|
|
npm run build:server
|
|
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
# 复制一份到原来build路径
|
2024-04-23 18:38:01 +08:00
|
|
|
|
#cd $Build_Path
|
|
|
|
|
|
#rm -rf build.bak
|
|
|
|
|
|
#mv build build.bak
|
|
|
|
|
|
#scp -r $Code_Path/build ./
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
2024-04-23 18:38:01 +08:00
|
|
|
|
pm2 restart pm2.json
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
# 重新加载 Nginx 配置
|
|
|
|
|
|
/home/pdl/nginx/sbin/nginx -s reload
|
2024-01-15 11:44:36 +08:00
|
|
|
|
|
2024-04-23 16:21:05 +08:00
|
|
|
|
# 检查 Nginx 是否重启成功
|
|
|
|
|
|
if [ "$?" -eq "0" ]; then
|
|
|
|
|
|
echo -e "\e[1;42m restart nginx OK! \e[0m"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo -e "\e[1;31m restart nginx FAILED! \e[0m"
|
|
|
|
|
|
fi
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
pm2.json配置
|
|
|
|
|
|
```json
|
|
|
|
|
|
{
|
|
|
|
|
|
"apps": [{
|
|
|
|
|
|
"name": "gitlink-ssr",
|
|
|
|
|
|
"script": "buildserver/bundle.js",
|
|
|
|
|
|
"watch": false,
|
|
|
|
|
|
"log_date_format": "YYYY-MM-DD HH:mm Z",
|
|
|
|
|
|
"exec_mode": "cluster",
|
|
|
|
|
|
"max_memory_restart": "300M", // 内存超过300m重启
|
|
|
|
|
|
"env": {
|
|
|
|
|
|
"NODE_ENV": "production",
|
|
|
|
|
|
"PORT": "8081" // 修改为ng给后端服务另配的端口
|
|
|
|
|
|
},
|
|
|
|
|
|
"instances": 4 // 实例数
|
|
|
|
|
|
}]
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|