Skip to content

Commit bf8a78f

Browse files
author
root
committed
nginx
1 parent a4d8761 commit bf8a78f

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
NGINX_CONFIG='/usr/local/nginx/conf/vhosts/sites-available'
2+
NGINX_SITES_ENABLED='/usr/local/nginx/conf/vhosts'
3+
WEB_DIR='/home/vagrant/sync/example'
4+
SED=`which sed`
5+
CURRENT_DIR=`dirname $0`
6+
7+
if [ -z $1 ]; then
8+
echo "No domain name given"
9+
exit 1
10+
fi
11+
DOMAIN=$1
12+
13+
# check the domain is roughly valid!
14+
PATTERN="^([[:alnum:]]([[:alnum:]\-]{0,61}[[:alnum:]])?\.)+[[:alpha:]]{2,6}$"
15+
if [[ "$DOMAIN" =~ $PATTERN ]]; then
16+
DOMAIN=`echo $DOMAIN | tr '[A-Z]' '[a-z]'`
17+
echo "Creating hosting for:" $DOMAIN
18+
else
19+
echo "invalid domain name"
20+
exit 1
21+
fi
22+
23+
#Replace dots with underscores
24+
SITE_DIR=`echo $DOMAIN | $SED 's/\./_/g'`
25+
26+
# Now we need to copy the virtual host template
27+
CONFIG=$NGINX_CONFIG/$DOMAIN.conf
28+
sudo cp $CURRENT_DIR/virtual_host.template $CONFIG
29+
sudo $SED -i "s/DOMAIN/$DOMAIN/g" $CONFIG
30+
sudo $SED -i "s!ROOT!$WEB_DIR/$SITE_DIR!g" $CONFIG
31+
32+
# set up web root
33+
sudo mkdir $WEB_DIR/$SITE_DIR
34+
sudo chown nginx:nginx -R $WEB_DIR/$SITE_DIR
35+
sudo chmod 600 $CONFIG
36+
37+
# create symlink to enable site
38+
sudo ln -s $CONFIG $NGINX_SITES_ENABLED/$DOMAIN.conf
39+
40+
# reload Nginx to pull in new config
41+
sudo /usr/local/nginx/sbin/nginx -s reload
42+
43+
# put the template index.html file into the new domains web dir
44+
sudo cp $CURRENT_DIR/index.html.template $WEB_DIR/$SITE_DIR/index.html
45+
sudo $SED -i "s/SITE/$DOMAIN/g" $WEB_DIR/$SITE_DIR/index.html
46+
sudo chown nginx:nginx $WEB_DIR/$SITE_DIR/index.html
47+
48+
echo "Site Created for $DOMAIN"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title></title>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
</head>
6+
<body>
7+
SITE created...
8+
</body>
9+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server {
2+
server_name www.DOMAIN DOMAIN;
3+
4+
root ROOT;
5+
6+
access_log /var/log/nginx/DOMAIN.access.log;
7+
8+
index index.html index.htm;
9+
10+
# serve static files directly
11+
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
12+
access_log off;
13+
expires max;
14+
}
15+
16+
location ~ /\.ht {
17+
deny all;
18+
}
19+
}

0 commit comments

Comments
 (0)