From 9697d0e8119b87ebf206c1c224ef6e3b5c99e984 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Thu, 24 Mar 2022 12:45:26 +0800 Subject: [PATCH 1/2] feat: add deploy conf --- deploy.sh | 12 ++++++++ nginx.conf | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 deploy.sh create mode 100644 nginx.conf diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..34510b3a --- /dev/null +++ b/deploy.sh @@ -0,0 +1,12 @@ +#! /bin/bash + +cd /apps/think +git checkout main +git pull + +pnpm install +pnpm run build +pnpm run pm2 + +pm2 startup +pm2 save diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..1004584d --- /dev/null +++ b/nginx.conf @@ -0,0 +1,86 @@ +upstream think_server { + server 127.0.0.1:5001; + keepalive 64; +} + +upstream think_client { + server 127.0.0.1:5002; + keepalive 64; +} + +upstream think_wss { + server 127.0.0.1:5003; + keepalive 64; +} + +server { + listen 80; + server_name api.codingit.cn; + rewrite ^(.*)$ https://$host$1 permanent; +} + +server { + listen 443 ssl http2; + server_name api.codingit.cn; + + ssl_certificate /apps/ssl/api.codingit.cn/api.codingit.cn.pem; + ssl_certificate_key /apps/ssl/api.codingit.cn/api.codingit.cn.key; + ssl_session_timeout 5m; + + client_max_body_size 100m; + + + location /think/wss { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header X-Nginx-Proxy true; + proxy_cache_bypass $http_upgrade; + proxy_pass http://think_wss; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /think { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Nginx-Proxy true; + proxy_cache_bypass $http_upgrade; + proxy_pass http://think_server; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} + +server { + listen 80; + server_name think.codingit.cn; + rewrite ^(.*)$ https://$host$1 permanent; +} + +server { + listen 443 ssl http2; + server_name think.codingit.cn; + + ssl_certificate /apps/ssl/think.codingit.cn/think.codingit.cn.pem; + ssl_certificate_key /apps/ssl/think.codingit.cn/think.codingit.cn.key; + ssl_session_timeout 5m; + + + location / { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header X-Nginx-Proxy true; + proxy_cache_bypass $http_upgrade; + proxy_pass http://think_client; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file From ddaa251afc0b3b43720e21013d484d0abf8d8720 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Thu, 24 Mar 2022 13:34:06 +0800 Subject: [PATCH 2/2] fix: improve deploy --- deploy.sh => bin/deploy.sh | 0 bin/update.sh | 11 +++++++++++ package.json | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) rename deploy.sh => bin/deploy.sh (100%) create mode 100644 bin/update.sh diff --git a/deploy.sh b/bin/deploy.sh similarity index 100% rename from deploy.sh rename to bin/deploy.sh diff --git a/bin/update.sh b/bin/update.sh new file mode 100644 index 00000000..a54e09a0 --- /dev/null +++ b/bin/update.sh @@ -0,0 +1,11 @@ +#! /bin/bash + +cd /apps/think +git checkout main +git pull + +pnpm install +pnpm run build + +pm2 restart @think/server +pm2 restart @think/client diff --git a/package.json b/package.json index 54967dc6..ff8c468c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "start": "concurrently \"pnpm:start:*\"", "start:server": "pnpm run --dir packages/server start", "start:client": "pnpm run --dir packages/client start", - "pm2": "concurrently \"pnpm:pm2:*\"", + "pm2": "pnpm run pm2:server && pnpm run pm2:client", "pm2:server": "pnpm run --dir packages/server pm2", "pm2:client": "pnpm run --dir packages/client pm2", "format": "prettier --write --parser typescript \"packages/**/*.ts?(x)\""