Commit a812506b authored by Vitaly Lipatov's avatar Vitaly Lipatov

add update_nginx.sh script

parent a2f31d58
#!/bin/sh
. ./functions
# TODO: static-fallback
# TODO: for WP only
print_nginx_conf()
{
cat <<EOF
# generated by $(realpath $0)
error_page $ECODE = @cache-$NAME;
location @fallback-$NAME {
root $DROOT;
proxy_pass $UPSTREAM;
include include/trans-proxy.conf;
# rewrite to cache if allowed
include include/check-skip-cache.inc;
if (\$skip_cache = 0) {
return $ECODE;
}
access_log /var/log/nginx/$ACONF-fallback-access.log logdetail;
error_log /var/log/nginx/$ACONF-fallback-error.log;
}
location @cache-$NAME {
root $DROOT;
proxy_pass $UPSTREAM;
include include/store-hour-proxy.conf;
access_log /var/log/nginx/$ACONF-cache-access.log logdetail;
error_log /var/log/nginx/$ACONF-cache-error.log;
}
location = /$NAME/server-status/ {
proxy_pass $UPSTREAM;
include include/trans-proxy.conf;
access_log /var/log/nginx/$ACONF-access.log logdetail;
}
location = /$NAME {
return 301 /$NAME/$is_args$args;
}
location /$NAME/ {
root $DROOT;
# Вместо несуществующих jpg, png, gif отдаём приготовленную картинку
include include/static-stub.conf;
# пробуем отдать напрямую статикой, не получится - на @fallback
include include/static-fallback-$NAME.conf;
# TODO: nginx: [emerg] named location "@injection-error_406" can be on the server level only in /etc/nginx/include/stop-injection.conf:65
#include include/stop-injection.conf;
proxy_pass $UPSTREAM;
include include/trans-proxy.conf;
# rewrite to cache if allowed
include include/check-skip-cache.inc;
if (\$skip_cache = 0) {
return $ECODE;
}
access_log /var/log/nginx/$ACONF-access.log logdetail;
error_log /var/log/nginx/$ACONF-error.log;
}
EOF
}
print_upstream_conf()
{
[ -n "$PHPHOST" ] || PHPHOST="$VEIP"
cat <<EOF
upstream $UPSTREAMNAME {
# server $VEIP;
server $PHPHOST;
}
EOF
}
TASK="$1"
echo "$TASK" | grep -q "ves/" || TASK="ves/$1.task"
load_config "$TASK"
DROOT=$HOSTHOME/$AUSER/www/$BASESITE
UPSTREAMNAME="upstream-$ACONF"
UPSTREAM="http://$UPSTREAMNAME"
VEPORT=$(printf "%03d" $(($VEID-100)))
ECODE=$((430+$VEID-100))
echo "VEPORT: $VEPORT ECODE: $ECODE"
print_nginx_conf >$NGINXSUBDIR/$NAME.conf
if ! grep -q $UPSTREAMNAME /etc/nginx/httpconf-enabled.d/upstream_$ACONF.conf ; then
print_upstream_conf >/etc/nginx/httpconf-enabled.d/upstream_$ACONF.conf
fi
#!/bin/sh
. ./functions
. ./base.task || exit
for i in $NGINXSUBDIR/*.conf ; do
grep "update_nginx.sh" $i || continue
N=$(basename $i .conf)
echo "Updating $N ..."
./update_nginx.sh $N
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment