nginx、git、node.js安装略过。
使git pull或者git push不需要输入密码操作方法
非docker安装nginx!!!
姊妹篇(docker安装nginx):shell脚本发布docker-nginx vue2 项目示例
pro_build.sh
注意:#!/bin/bash -ilex
,如果jenkins远程ssh登录执行sh脚本,并且jekins安装在docker容器里面
,这句代码很有必要。
#!/bin/bash -ilex
#环境变量
who am i
set -e
#当前vue2demo目录
cd /opt/vue2demo
echo "拉取gitlib最新代码..."
git status && git pull
#if判断其实是多余的,set -e 当$? 不等于0时候已经退出了
if [[ $? -ne 0 ]]
then
echo "拉取gitlib最新代码失败,准备退出"
exit 1
fi
echo "拉取gitlib最新代码成功"
rm -rf dist/
echo "删除旧的dist打包目录"
echo "npm install --> 准备安装依赖..."
#npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm install
echo "npm run build --> 准备构建打包..."
npm run build
echo "准备发布到nginx 目录..."
echo "发布完毕"
nginx配置:
server {
listen 8888;
server_name 192.168.1.105;
charset utf-8;
#proxy_intercept_errors on;
#ui
root /opt/vue2demo/dist;
#serve
#服务springboot见文章:https://blog.csdn.net/HSJ0170/article/details/137103193
location ^~/api {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://192.168.1.105:55530;
#启用支持websocket连接
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
启动:
cd /user/local/nginx/sbin
#重新加载
./nginx -s reload