|
本帖最后由 re2d2 于 2015-4-13 08:20 编辑
一、准备一台虚拟机:
ip:192.168.1.214
关闭防火墙和设置selinux为disabled
1
2
3
| [iyunv@localhost ~]service iptables stop
[iyunv@localhost ~]chkconfig iptables off
[iyunv@localhost ~]sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
|
二、在安装Nginx之前,首先要确保安装了gcc,openssl-devel,pcre-devel,zilb-devel软件库。
安装pcre是使nginx支持http rewrite模块,安装也很简单,过程如下:
1
2
3
4
5
6
7
8
9
10
| 下载官网:
[iyunv@localhost ~]#yum install -y pcre-devel
[iyunv@localhost ~]#tar zxvf nginx-1.2.9.tar.gz
[iyunv@localhost ~]#cd nginx-1.2.9
[iyunv@localhost ~]#./configure \
--with-http_stub_status_module \ #启用nginx的nginxstauts功能,以监控nginx当前状态
--prefix=/application/nginx \ #Nginx的安装路径
--with-http_gzip_static_module #启用HttpGzip模块
make && make install
#如此,pcre就安装好了!
|
提示:其实Nginx的安装也很简单,默认下,经过编译安装的Nginx已经有了很多可以用的模块了。
我们可以用"./configure --help"查看每个模块的使用情况。
例如:不安装http_ssi模块
执行:--without-http_ssi_module
三、Nginx的安装过程如下:
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
| [iyunv@localhost ~]# tar zxvf nginx-1.6.0.tar.gz
[iyunv@localhost ~]# cd nginx-1.6.0
[iyunv@localhost ~]# ./configure
--prefix=/usr/local \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre
[iyunv@localhost ~]# make && make install
#启动Nginx
[iyunv@localhost ~]#/usr/sbin/nginx
#查看端口是否启动
[iyunv@localhost ~]# netstat -lntup|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1072/nginx
|
Nginx安装完成之后,在浏览器中输入IP:192.168.1.214
如图出现Nginx的欢迎界面,表示已经成功了!
其中Nginx还有一些常用命令:
1
2
3
4
5
6
7
8
9
10
11
| #检查语法
/usr/sbin/nginx –t
#平滑重启
/usr/sbin/nginx –sreload
#不间断服务重启,将 pid 行程重跑 (restart)
Kill –HUP `cat /opt/nginx/logs/nginx.pid`
#关闭
Kill 进程号
|
四、添加编译模块
安装好nginx之后,如果现在需要添加一个未被编译安装的模块,我们该如何做呢?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| nginx -V ==>可以查看原来编译时都带了哪些参数
添加的参数:
--with-http_stub_status_module
--with-http_ssl_module
--with-http_realip_module
步骤如下:
1. 使用参数重新配置: ./configure
--user=nginx \
--group=nginx \
--prefix=/application/nginx1.6.2 \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_ssl_module--add-module=../nginx_upstream_hash-0.3.1/\
--add-module=../gnosek-nginx-upstream-fair-2131c73/
2. 编译:
make
|
注意:不要make install,否则就是覆盖安装
还有可以通过官方查看模块安装例子http://nginx.org/en/docs/
|
|
|
|
|
|
|