Skip to content

Instantly share code, notes, and snippets.

@Sid3y1
Created August 23, 2016 08:41
Show Gist options
  • Save Sid3y1/c746f8351c35b7c59212f7eded1d49f9 to your computer and use it in GitHub Desktop.
Save Sid3y1/c746f8351c35b7c59212f7eded1d49f9 to your computer and use it in GitHub Desktop.
nginx reverse proxy script
#!/bin/bash
if [[ ! $3 ]]
then
echo "Usage ./rproxy.sh name ip port"
exit 1
fi
if [[ -f /etc/nginx/sites-enabled/$1 ]]
then
echo "_______________________________________________"
echo " "
echo " cat /etc/nginx/sites-enabled/$1 "
echo "_______________________________________________"
cat /etc/nginx/sites-enabled/$1
echo "_______________________________________________"
echo " "
read -p "Le fichier existe remplacer ? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "File will be overwrited"
else
echo "Abord"
exit 1
fi
fi
echo "
#Automaticaly added by a super script
server {
listen 80;
server_name $1 www.$1;
access_log /var/log/nginx/$1.access.log;
location / {
proxy_pass http://$2:$3/;
}
}
" > /etc/nginx/sites-enabled/$1
/etc/init.d/nginx reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment