Reverse proxy to antother IP

Post Reply
User avatar
dpeca
Site Admin
Posts: 239
Joined: Fri Jun 19, 2020 9:59 am
Reverse proxy to antother IP

Post by dpeca »

You can install template that will do reverse proxy.

Code: Select all

wget -nv -O /usr/local/vesta/data/templates/web/nginx/forward.sh http://dl.mycity.tech/vesta/vesta-cp-nginx-tpl/fwd-http2/forward.sh
wget -nv -O /usr/local/vesta/data/templates/web/nginx/forward.tpl http://dl.mycity.tech/vesta/vesta-cp-nginx-tpl/fwd-http2/forward.tpl
wget -nv -O /usr/local/vesta/data/templates/web/nginx/forward.stpl http://dl.mycity.tech/vesta/vesta-cp-nginx-tpl/fwd-http2/forward.stpl
chmod a+x /usr/local/vesta/data/templates/web/nginx/forward.sh
If you want to apply it to some domain:

Code: Select all

user='your-vesta-user' # enter
domain='your-domain.com' # enter
newip='xxx.xxx.xxx.xxx' #  enter

echo "$newip" > /home/$user/conf/web/forward-all.txt
/usr/local/vesta/bin/v-change-web-domain-proxy-tpl "$user" "$domain" 'forward' 'txt' 'yes'
Last 'yes' is to restart nginx after each domain, so it can be 'no' and then restart manuly.

If you want that all domains goes to the same IP, you can set it globaly instead of per account:

Code: Select all

echo "$newip" > /home/forward-all.txt
To apply redirection to all domains on the server:

Code: Select all

    newip='xxx.xxx.xxx.xxx' #  enter
    echo "$newip" > /home/forward-all.txt
    for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
        if [ ! -f "/usr/local/vesta/data/users/$user/user.conf" ]; then
            continue;
        fi
        for domain in $(/usr/local/vesta/bin/v-list-web-domains $user plain |cut -f 1); do
            /usr/local/vesta/bin/v-change-web-domain-proxy-tpl "$user" "$domain" 'forward' 'txt' 'no'
            echo "=== Redirected: $domain"
        done
    done
    service nginx reload

Tags:


Post Reply