-
-
Save leninhasda/0258c43877f9b8101ebd to your computer and use it in GitHub Desktop.
a simple .sh file that i use to create new virtual host and directory structure in nginx for web application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
listen [::]:80; | |
root /home/lenin/dev/devfolderroot/web; | |
index index.php index.html index.htm; | |
server_name domainname; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
autoindex on; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
isRoot(){ | |
if [ "$(id -u)" != "0" ]; then | |
echo "WARNING: This script must be run as root. Script terminated!!" | |
exit 1 | |
fi | |
} | |
# check if root user | |
isRoot | |
# get the app name | |
echo "Enter Project Name (all lower case) " | |
read appname | |
# replace space | |
appname="$(echo $appname | sed 's/ /-/g')" | |
appnameDev="$appname.dev" | |
# make app directory in dev | |
# and set permission | |
mkdir ~/dev/$appnameDev | |
mkdir ~/dev/$appnameDev/web | |
chmod 777 -R ~/dev/$appnameDev | |
# edit host | |
#hostedit="127.0.0.1 $appname.ice9\n127.0.0.1 www.$appname.ice9" | |
#echo -e $hostedit >> /etc/hosts | |
# create server config file | |
cp /etc/nginx/sites-available/base /etc/nginx/sites-available/$appname | |
sed -i "s/devfolderroot/$appnameDev/g" /etc/nginx/sites-available/$appname | |
sed -i "s/domainname/$appnameDev/g" /etc/nginx/sites-available/$appname | |
echo -e $confedit >> "/etc/nginx/sites-available/$appname" | |
# enable site | |
ln -s /etc/nginx/sites-available/$appname /etc/nginx/sites-enabled/$appname | |
# reload & restart server | |
service nginx reload | |
service nginx restart | |
echo "$appname created!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment