87 lines
2.2 KiB
Plaintext
Raw Normal View History

2016-05-30 00:47:27 +02:00
#!/bin/sh
echo ""
echo "Welcome to ngxproxy utility."
echo "We're about to create a new vhost."
echo ""
2016-05-30 07:43:10 +02:00
while [ "$NAME" == "" ]; do
read -p "Name: " NAME
done
while [ "$DOMAIN" == "" ]; do
read -p "Domain: " DOMAIN
2016-05-30 12:55:55 +02:00
if [ "$(dig +short ${DOMAIN})" == "" ]; then
echo "WARNING: ${DOMAIN} couldn't be resolved. It may not work!"
echo "HINT: Is this domain correct? Did you update your DNS zone?"
fi
2016-05-30 07:43:10 +02:00
done
while [ "$CONTAINER" == "" ]; do
read -p "Container: " CONTAINER
ping -c 1 ${CONTAINER} >/dev/null 2>&1
2016-05-30 12:55:55 +02:00
if [ "$?" != "0" ]; then
echo "WARNING: ${CONTAINER} seems to be unavailable. It may not work!"
echo "HINT: Did you correctly link the container?"
fi
2016-05-30 07:43:10 +02:00
done
2016-05-30 00:47:27 +02:00
read -p "Port (blank means 80): " PORT
2016-05-30 07:43:10 +02:00
if [ "$PORT" == "" ]; then
PORT="80"
fi
2016-05-30 00:47:27 +02:00
while [[ "$HTTPS" != "y" && "$HTTPS" != "n" ]]; do
read -p "HTTPS [y/n]: " HTTPS
done
if [ "$HTTPS" == "y" ]; then
2016-05-30 07:43:10 +02:00
while [ ! -f "$CERTIFICATE_PATH" ]; do
read -p "Certificate path: " CERTIFICATE_PATH
done
while [ ! -f "$KEY_PATH" ]; do
read -p "Certificate key path: " KEY_PATH
done
2016-05-30 00:47:27 +02:00
cp /etc/nginx/conf/vhost_https.conf /sites-enabled/${NAME}.conf
2016-05-30 07:43:10 +02:00
2016-05-30 00:47:27 +02:00
sed -i \
-e "s|<CERTIFICATE_PATH>|${CERTIFICATE_PATH}|g" \
-e "s|<KEY_PATH>|${KEY_PATH}|g" \
/sites-enabled/${NAME}.conf
2016-05-30 07:43:10 +02:00
2016-05-30 00:47:27 +02:00
while [[ "$HEADERS" != "y" && "$HEADERS" != "n" ]]; do
read -p "Secure headers [y/n]: " HEADERS
done
if [ "$HEADERS" == "y" ]; then
sed -i 's|#include /etc/nginx/conf/headers_params|include /etc/nginx/conf/headers_params|g' \
/sites-enabled/${NAME}.conf
fi
else
cp /etc/nginx/conf/vhost_http.conf /sites-enabled/${NAME}.conf
fi
2016-05-30 07:43:10 +02:00
while [ "$MAX_BODY_SIZE" == "" ]; do
read -p "Max body size (value in MB, or n): " MAX_BODY_SIZE
done
2016-05-30 00:47:27 +02:00
if [ "$MAX_BODY_SIZE" != "n" ]; then
2016-05-30 07:43:10 +02:00
sed -i "s|#client_max_body_size <MAX_BODY_SIZE>|client_max_body_size ${MAX_BODY_SIZE}|g" \
/sites-enabled/${NAME}.conf
2016-05-30 00:47:27 +02:00
fi
sed -i \
2016-05-30 07:43:10 +02:00
-e "s|<DOMAIN>|${DOMAIN}|g" \
-e "s|<CONTAINER>|${CONTAINER}|g" \
-e "s|<PORT>|${PORT}|g" \
/sites-enabled/${NAME}.conf
2016-05-30 00:47:27 +02:00
echo ""
echo "It's done : ${NAME}.conf has been generated."
echo "Restart boring-nginx to apply these modifications."
echo ""
2016-05-30 00:48:53 +02:00
exit 0