Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Beaudev simple script to add a nginx vhost reverse proxying to a docker instance
# add vhost reverse proxy for new docker instance for nginx and restart nginx
# use like this : do_nginx_proxy_vhost
function do_nginx_proxy_vhost() {
[ -z $1 -o -z $2 ] && echo "Give host and address" && return
[ -f /etc/nginx/sites-available/proxy_reverse_$host ] && (echo "Updating proxy for host: $host" && sudo rm /etc/nginx/sites-enabled/proxy_reverse_$host) || echo "Creating proxy for host: $host"
sudo bash <<EOF
echo 'server {
server_name $host;
location / {
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 $address;
}' &> /etc/nginx/sites-available/proxy_reverse_$host
sudo ln -s /etc/nginx/sites-available/proxy_reverse_$host /etc/nginx/sites-enabled/proxy_reverse_$host
sudo service nginx restart

This comment has been minimized.

Copy link

@askz askz commented May 16, 2016

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment