一、阿里云ECS云服务器搭建Docker,nginx 环境服务
(一)安装docker(https://file.xdclass.net/note/2022/79-vue3%2Bnode%2Bmysql/vue3%2Bnode%2Bmysql%E5%85%A8%E6%A0%88%E9%A1%B9%E7%9B%AE%E8%AF%BE%E7%A8%8B.html)
(二)安装nginx
1、(安装也参考https://file.xdclass.net/note/2022/79-vue3%2Bnode%2Bmysql/vue3%2Bnode%2Bmysql%E5%85%A8%E6%A0%88%E9%A1%B9%E7%9B%AE%E8%AF%BE%E7%A8%8B.html)
2、数据卷的挂载
①进行目录的复制,/usr/local/docker下面有没有nginx,没有就逐级创建目录,手动创建/usr/local/docker/nginx/conf/文件夹
docker ps -a # 查看当前nginx服务的ID
docker cp ID:/etc/nginx/nginx.conf /usr/local/docker/nginx/conf # 将配置文件复制到自己的本地
②创建nginx数据卷挂载目录 ,注意:我是将nginx数据挂载在/usr/local/docker/nginx/文件夹下
cd /data/nginx # 进入data/nginx目录下,在这个目录下进行数据的挂载
mkdir www # 用于挂载html文件的配置,网站的根目录数据
mkdir logs # 挂载日志文件位置
③因为nginx的配置文件需要直接挂载,需要给定权限
cd /data/nginx/conf
chmod 777 nginx.conf
④关闭并删除前面启动的nginx
docker stop dagaer-nginx # 关闭
docker rm dagaer-nginx # 删除
⑤启动nginx并进行数据挂载
docker run -p 3306:3306 --name dagaer_mysql -v /usr/local/docker/mysql/conf:/etc/mysql -v /usr/local/docker/mysql/logs:/var/log/mysql -v /usr/local/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Jac15188891862 -d mysql:5.7
进入nginx目录,启动服务
cd /usr/local/nginx/sbin
./nginx -t
重启服务
./nginx -s reload
打开配置文件配置https协议
vim /usr/local/docker/nginx/conf/nginx.conf
下次ssl证书到期后,进需要重新进入到Nginx目录
1、cd /usr/local/nginx/sbin
2、./nginx
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
https://blog.csdn.net/qq_42483257/article/details/129924655
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
https://www.cnblogs.com/qcwblog/p/13494818.html
阿里云服务器在线安装nginx
https://blog.csdn.net/weixin_45462732/article/details/110356865
Linux下卸载删除nginx(阿里云服务器)
https://blog.csdn.net/qq_62262918/article/details/138709701
https://blog.51cto.com/u_13527/11365348
二、pm2 的一些操作
cd /usr/local/node
# 启动、停止、重启、重载、删除配置文件中所有项目
pm2 start ecosystem.config.js
pm2 stop ecosystem.config.js
pm2 restart ecosystem.config.js
pm2 reload ecosystem.config.js
pm2 delete ecosystem.config.js
pm2 start app.js
pm2 stop app.js
pm2 restart app.js
pm2 list
pm2 delete app.js
pm2 start app.js --name app
PM2入门及其常用命令(下面有如何自动重启服务功能)
https://blog.csdn.net/lemon_TT/article/details/130018781
PM2让Node.js项目在服务器崩溃重启后,能自启动!
https://cloud.tencent.com/developer/article/1906613
三、git的常用命令
上传
git add .
git commit -m "xxx"
git push origin
拉取
git fetch origin
git pull origin
四、vite打包时路径错误
在vite.config.js中设置
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
base: process.env.NODE_ENV === 'production' ? './' : '/',
})