使用 jenkins 为 nginx 增加上下文
每次需要在Nginx增加上下文,都需要添加如下两段
server.conf
upstream serverdownloadPage {
server 10.11.19.6:3023;
}
http.conf and https.conf
location ^~ /downloadPage/ {
proxy_redirect off;
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_pass http://serverdownloadPage;
}
既然每次都是重复的内容,只是需要修改部分字符串,当然要想办法用Jenkins去实现了。
脚本如下:
[root@mysql ~]# cat add_server.sh
#!/bin/bash
cat <<EOF>> /usr/local/nginx/conf/vhost/server.conf
upstream server$1 {
server $2:$3;
}
EOF
cat <<EOF> /tmp/vhosts.file
location ^~ /$1/ {
proxy_redirect off;
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_pass http://server$1;
}
EOF
sed -i '36r /tmp/vhosts.file' /usr/local/nginx/conf/vhost/http.conf
sed -i '41r /tmp/vhosts.file' /usr/local/nginx/conf/vhost/https.conf
如何增加上下文呢
./add_server.sh mmp 10.11.19.17 12999
同样Jenkins的配置也就简单了。
使用