1、安装工具包 wget、vim和gcc
yum install -y wget
yum install -y vim-enhanced
yum install -y make cmake gcc gcc-c++
2、下载nginx安装包
wget http://nginx.org/download/nginx-1.6.3.tar.gz
3、安装依赖包
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
4、解压nginx-1.6.3.tar.gz到/usr/local/目录下
tar -zxvf nginx-1.6.3.tar.gz -C /usr/local/
5、进行configure配置
进入nginx-1.6.3目录然后在执行./configure命令
[root@demo nginx-1.6.3]# ./configure --prefix=/usr/local/nginx
6、编译安装
[root@demo nginx-1.6.3]# make && make install
7、启动Nginx,启动完之后检查nginx是否已经正常启动,看到如下信息说明正常启动
[root@demo nginx-1.6.3]# /usr/local/nginx/sbin/nginx
[root@demo nginx-1.6.3]# ps -ef | grep nginx
root 8692 1 0 19:26 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 8693 8692 0 19:26 ? 00:00:00 nginx: worker process
root 8946 22540 0 19:26 pts/0 00:00:00 grep nginx
[root@demo nginx-1.6.3]#
如果要关闭nginx,我们可以使用如下命令:
[root@demo nginx-1.6.3]# /usr/local/nginx/sbin/nginx -s stop
如果想要重新热启动nginx,则使用如下命令:
[root@demo nginx-1.6.3]# /usr/local/nginx/sbin/nginx -s reload
如出现以下错误,请执行:
[root@demo nginx-1.6.3]# /usr/local/nginx/sbin/nginx -s reloadnginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
[root@demo nginx-1.6.3]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
8、开机自动启动
即在/etc/rc.local
增加启动代码就可以了。
增加一行:
/usr/local/nginx/sbin/nginx
授权:
[root@demo nginx-1.6.3]# chmod 755 /etc/rc.local