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
|
源码安装
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
# tar xf pcre-8.36.tar.bz2
# cd pcre-8.36
# ./configure
# make
# make install
或者yum安装
# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel \
pcre pcre-devel openssl
bzip2
-devel libxml2 libxml2-devel curl-devel \
libjpeg libjpeg-devel libpng libpng-devel openssl-devel libevent libevent-devel
(2)安装Nginx
首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -r nginx
# useradd -r -g nginx -s /sbin/nologin nginx
接着开始编译和安装:
# wget http://nginx.org/download/nginx-1.10.1.tar.gz
# tar xf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# ./configure \
--prefix=
/usr/local/nginx
\
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-
file
-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-http_v2_module \
--with-http_mp4_module
# make && make install
参考配置文件:
# cat nginx.conf
user nginx;
worker_processes 8;
worker_rlimit_nofile 102400;
error_log
/data0/log/nginx/error
.log notice;
pid
/data0/log/nginx/nginx
.pid;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application
/octet-stream
;
log_format nginx_log
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
;
client_header_timeout 30s;
client_body_timeout 30s;
send_timeout 60s;
client_max_body_size 350m;
sendfile on;
keepalive_timeout 65;
proxy_buffers 8 128k;
proxy_buffer_size 128k;
gzip
on;
server {
listen 80 default_server;
server_name _;
return
404;
}
include vhosts/*.conf;
}
虚拟主机配置参考:
# cat domain.conf
upstream hall.tg-game.cn {
server 10.192.23.204:8080 max_fails=3 fail_timeout=30s;
server 10.192.23.221:8080 max_fails=3 fail_timeout=30s;
ip_hash;
}
server {
listen 80;
server_name hall.tg-game.cn;
location / {
root html;
index index.html index.htm;
proxy_pass http:
//hall
.tg-game.cn/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 512k;
access_log
/data0/log/nginx/hall
.tg-game.cn.log nginx_log;
# allow 101.254.183.162;
# deny all;
}
}
脚本安装:
#!/bin/bash
#
# Install_Nginx.sh
#
#yum install pcre openssl#
yum -y
install
gcc gcc-c++ autoconf automake zlib zlib-devel \
pcre pcre-devel openssl
bzip2
-devel libxml2 libxml2-devel curl-devel \
libjpeg libjpeg-devel libpng libpng-devel openssl-devel libevent libevent-devel 2>
/tmp/yum
.log 1>
/dev/null
||
exit
6
#add nginx#
groupadd -r nginx ||
echo
"group 'nginx' already exists"
useradd
-r -g nginx -s
/sbin/nologin
nginx ||
echo
"user 'nginx' already exists"
#install nginx#
cd
/usr/local/src/
wget http:
//nginx
.org
/download/nginx-1
.10.1.
tar
.gz 2>
/tmp/down_nginx
.log 1>
/dev/null
&&
echo
"download success"
||
exit
6
tar
xf nginx-1.10.1.
tar
.gz
cd
nginx-1.10.1
.
/configure
\
--prefix=
/usr/local/nginx
\
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-
file
-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-http_v2_module\
--with-http_mp4_module 2>
/tmp/nginx_config
.log 1>
/dev/null
if
[ $? != 0 ];
then
echo
"./configure false"
exit
3
fi
make
2>
/tmp/nginx_make
.log 1>
/dev/null
if
[ $? != 0 ];
then
echo
"make false"
exit
3
fi
make
install
2>
/tmp/nginx_make_install
.log 1>
/dev/null
if
[ $? != 0 ];
then
echo
"make install false"
exit
3
else
echo
"Install_Nginx success"
cd
/tmp
&&
rm
-rf yum.log nginx_config.log nginx_make.log nginx_make_install.log down_nginx.log
fi
|
本文转自 wpf926 51CTO博客,原文链接:http://blog.51cto.com/wupengfei/1958133,如需转载请自行联系原作者