Скрипт добавления хоста в nginx

Вызов скрипта с аргументами: имя-домена место/с/файлами.

 

#!/bin/bash
cat <<EOF> /etc/nginx/conf.d/$1.conf
server {
		listen 80;
		server_name $1 www.$1;
		error_page 404 = @fallback;
		location / {
			proxy_pass http://127.0.0.1:80;
			proxy_redirect http://$1:80/ /;
			proxy_set_header Host \$host;
			proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
			proxy_set_header X-Real-IP \$remote_addr;
		}
		location ~* ^.+\\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
			root $2;
		}
		location @fallback {
			proxy_pass http://127.0.0.1:80;
			proxy_set_header Host \$host;
			proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
			proxy_set_header X-Real-IP \$remote_addr;
		}
	}
EOF