Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的小文件并发能力在同类型的网页服务器中表现较好。
Nginx的编译安装:
1.下载Openssl
1
|
[root@Node1 ~]
# wget http://www.openssl.org/source/openssl-1.0.2.tar.gz
|
2.下载nginx
1
|
[root@Node1 ~]
# wget http://nginx.org/download/nginx-1.6.2.tar.gz
|
3.解压软件
1
2
|
[root@Node1 ~]
# tar zxf openssl-1.0.2.tar.gz
[root@Node1 ~]
# tar zxf nginx-1.6.2.tar.gz
|
4.编译Nginx
1
2
|
[root@Node1 ~]
# cd nginx-1.6.2
[root@Node1 nginx-1.6.2]
# ./configure --user=www --group=www --prefix=/data/nginx1.6.2 --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-openssl=/root/openssl-1.0.2
|
注意:编译nginx添加ssl支持,如果需要编译的openssl,是不需要编译opensll,--with-openssl=DIR DIR是openssl的源码路径,不是openssl的安装路径,否则make时将出错:
1
2
3
4
5
6
7
8
9
10
11
12
|
make
[1]: Entering directory `
/root/nginx-1
.6.2'
cd
/server/openssl
\
&&
make
clean \
&& .
/config
--prefix=
/server/openssl/openssl
no-shared no-threads \
&&
make
\
&&
make
install
make
[2]: Entering directory `
/server/openssl
'
make
[2]: *** No rule to
make
target `clean'. Stop.
make
[2]: Leaving directory `
/server/openssl
'
make
[1]: *** [
/server/openssl/openssl/include/openssl/ssl
.h] Error 2
make
[1]: Leaving directory `
/root/nginx-0
.7.61'
make
: *** [build] Error 2
|
如果出现
1
2
3
4
|
.
/configure
: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or
install
the PCRE library into the system, or build the PCRE library
statically from the
source
with nginx by using --with-pcre=<path> option.
|
这说明没有安装pcre & pcre-devel包,这里yum安装
1
|
[root@Node1 nginx-1.6.2]
# yum -y install pcre pcre-devel
|
5.安装Nginx
1
2
3
|
[root@Node1 nginx-1.6.2]
# make
[root@Node1 nginx-1.6.2]
# make install
|
6.启动之前检查nginx
1
2
3
4
|
[root@Node1 nginx-1.6.2]
# /data/nginx1.6.2/sbin/nginx -t
nginx: the configuration
file
/data/nginx1
.6.2
/conf/nginx
.conf syntax is ok
nginx: [emerg] getpwnam(
"www"
) failed
nginx: configuration
file
/data/nginx1
.6.2
/conf/nginx
.conf
test
failed
|
检查发现是没有运行用户,新增www账户
1
2
|
[root@Node1 nginx-1.6.2]
# groupadd www
[root@Node1 nginx-1.6.2]
# useradd -g www -s /sbin/nologin -d /dev/null www
|
7.再次检查
[root@Node1 nginx-1.6.2]# /data/nginx1.6.2/sbin/nginx -t
nginx: the configuration file /data/nginx1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx1.6.2/conf/nginx.conf test is successful
8.启动Nginx
1
|
[root@Node1 nginx-1.6.2]
# /data/nginx1.6.2/sbin/nginx
|
9.检查端口
1
2
|
[root@Node1 nginx-1.6.2]
# netstat -ntlup |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19849
/nginx
|
10.检查进程
1
2
3
4
|
[root@Node1 nginx-1.6.2]
# ps aux |grep nginx
root 19849 0.0 0.0 22664 852 ? Ss 11:19 0:00 nginx: master process
/data/nginx1
.6.2
/sbin/nginx
www 19850 0.0 0.1 23100 1448 ? S 11:19 0:00 nginx: worker process
root 19858 0.0 0.0 103244 856 pts
/0
S+ 11:21 0:00
grep
nginx
|
11.网站访问
本文转自 rong341233 51CTO博客,原文链接:http://blog.51cto.com/fengwan/1617167