-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx_on.sh
More file actions
162 lines (119 loc) · 4.16 KB
/
Copy pathnginx_on.sh
File metadata and controls
162 lines (119 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
if [ "$USER" != "root" ];then
echo "Please start the script with ROOT"
exit
fi
if [ ! "$1" ];then
echo "What is the folder of your web site ?"
exit
fi
function usage {
echo "
Usage:
$ sudo bash $0 /path/to/site [option]
or
# bash $0 /path/to/site [option]
Options:
on - Create a nginx.conf file in /path/to/file
Create a symbolic link to /etc/nginx/sites-enabled/
Restart Nginx
off - Delete the symbolic link in /etc/nginx/sites-enabled/
Restart Nginx
"
}
nginx_site=/etc/nginx/sites-enabled
nginx_local_conf="nginx.conf"
current_file=$(dirname "$1""$nginx_local_conf")
cd $current_file
current_folder=$(pwd)
number_of_folder=$(echo "$current_folder" | grep -o "/" | wc -l | sed s/\ //g)
number=$(($number_of_folder+1))
current_relative=$(echo "$current_folder" | cut -d/ -f "$number")
source_file="$current_folder"/"$nginx_local_conf"
destination_file="$nginx_site"/"$current_relative"_"$nginx_local_conf"
function makeNging {
if [ -f "$source_file" ];then
date=$(date '+%Y-%m-%d_%Ih%Mm%S')
mv "$source_file" "$current_folder"/"$date"_"$nginx_local_conf"
fi
echo "
#upstream myhost {
# PERL OR NODE
# server 127.0.0.1:3000;
#}
server {
listen 80;
server_name $1 www.$1;
access_log /var/log/nginx/$1.access.log;
error_log /var/log/nginx/$1.error.log;
try_files \$uri \$uri/ /index.php /index.html;
if (\$host = \"www.$1\") {
rewrite ^/(.*)$ http://$1/\$1 permanent;
}
### ======================= () =========
location / {
root $current_folder;
index index.html index.htm index.php;
if (!-f \$request_filename) {
# WORDPRESS
# rewrite ^/(.*)\$ /index.php?q=\$1 last;
# PERL OR NODE
# proxy_read_timeout 300;
# proxy_pass http://127.0.0.1:3000;
# proxy_set_header Host \$host;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-HTTPS 0;
}
}
## ======== PHP =============
# location ~ \.php$ {
# if (!-f \$request_filename) {
# return 404;
# }
# root $current_folder;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
# include fastcgi_params;
# }
if (\$request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 424;
}
if (\$http_user_agent ~* LWP::Simple|BBBike|msnbot|scrapbot) {
return 403;
}
if ( \$http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen) ) {
return 403;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
### ======================= SSL =========
#listen 443;
#ssl on;
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
#ssl_session_timeout 5m;
#ssl_protocols SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
#ssl_prefer_server_ciphers on;
}
" > "nginx.conf"
}
if [ "$2" == "on" ];then
makeNging "$current_relative"
rm "$destination_file" 2> /dev/null
mkdir -p /etc/nginx/sites-enabled/
ln -s "$source_file" "$destination_file"
chmod 755 "$destination_file"
/etc/init.d/php5-fpm restart 2> /dev/null
/etc/init.d/nginx restart 2> /dev/null
echo "Site: $current_relative --> $destination_file [ON]"
elif [ "$2" == "off" ];then
rm "$destination_file"
/etc/init.d/php5-fpm restart 2> /dev/null
/etc/init.d/nginx restart 2> /dev/null
echo "Site: $current_relative [OFF]"
else
echo "$1 to ON or OFF ?"
fi