forked from nbzdwss78/open-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·115 lines (93 loc) · 2.74 KB
/
install.sh
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
#!/bin/bash
# auth : gfw-breaker
sites=$(echo $(ls sites) | sed 's/\\n/ /')
for s in $*; do
if [[ " $sites " =~ " $s " ]]; then
targets="$s $targets"
fi
done
if [ $# -eq 0 ]; then
targets=$sites
fi
echo "you are going to install proxy for following sites:" $targets
sleep 3
NGINX_VERSION=1.13.3
PCRE_VERSION=8.41
ZLIB_VERSION=1.2.11
NGX_CONF_DIR=/usr/local/nginx/conf
mkdir -p /usr/local/nginx/content/cache
## install common tools
yum install -y gcc wget vim gcc-c++ openssl-devel bash-completion
## download
wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz"
wget "http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz"
wget --no-check-certificate "https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz"
git clone https://github.com/kaltura/nginx-vod-module.git
## install
tar xzf nginx-${NGINX_VERSION}.tar.gz && \
tar xzf pcre-${PCRE_VERSION}.tar.gz && \
tar xzf zlib-${ZLIB_VERSION}.tar.gz
cd nginx-${NGINX_VERSION} && \
./configure \
--with-http_sub_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-pcre=../pcre-${PCRE_VERSION} \
--with-zlib=../zlib-${ZLIB_VERSION} \
--add-module=../nginx-vod-module \
--with-file-aio \
--with-threads
if [ $? -ne 0 ]; then
echo "failed to compile nginx and modules, please check the installation log"
exit 1
fi
make -j4 && make install
cd ..
## configure
server_ip=$(ifconfig | grep "inet addr" | sed -n 1p | cut -d':' -f2 | cut -d' ' -f1)
#server_ip="nogfw.ml"
for site in $targets; do
sed -i "s/local_server_ip/$server_ip/g" sites/$site
sed -i "/## sites/a\\\\tinclude $site;" common/nginx.conf
cp sites/$site $NGX_CONF_DIR
done
cp common/*.conf $NGX_CONF_DIR
chmod +x common/nginx && cp common/nginx /etc/init.d
chkconfig nginx on
service nginx restart
## disable iptables temparorily for testing, should enable and add rules to it in production
service iptables stop
chkconfig iptables off
## print proxy information
function get_field(){
local site="$1"
local key="$2"
local value=$(grep $key sites/$site | sed -n 1p | awk '{print $2}' | sed 's/;//')
echo $value
}
echo -e "\nProxy information:\n"
for s in $targets; do
org_url=$(get_field $s proxy_pass)
proxy_port=$(get_field $s listen)
echo -e "http://$server_ip:$proxy_port \t->\t$org_url"
done | sort
echo