【转载自】http://blog.csdn.net/u010028869/article/details/50444801
软件下载
官网下载: http://nginx.org/en/download.html
版本号: nginx-1.8.0.tar.gz
开始安装
① 解压文件
[root@localhost ~]# cd /usr/local/software/
[root@localhost software]# tar -zxvf nginx-1.8.0.tar.gz
② 进步Nginx目录进行编译安装
[root@localhost local]# cd /usr/local/software/nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.8.0]# make & make install
③ 启动Nginx
[root@localhost local]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
常见错误
在进行./configure 命令的时候经常会因为缺少库文件而报错,如下:错误一:缺少gc++库文件
解决方式:在线安装gcc gcc-++
yum -y install gcc gcc-++ autoconf automake
错误二:缺少PCRE库
./configure: error: the HTTP rewrite module requires the PCRE library.
解决方式:安装pcre-devel解决问题
yum -y install pcre-devel
错误三:
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module –with-openssl= options.
解决方式:
yum -y install openssl openssl-devel
安装后继续执行configure命令,即可完成Nginx的安装
./configure --prefix=/usr/local/nginx
Nginx的启动、停止、重启
首先介绍如何查看Nginx的进程号:用命令:ps -ef|grep nginx 查看
[root@localhost local]# ps -ef|grep nginx
root 13421 1 0 02:55 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 13422 13421 0 02:55 ? 00:00:00 nginx: worker process
root 13448 7858 0 03:04 pts/0 00:00:00 grep --color=auto nginx
① 启动方式
【Nginx启动文件地址】 -c 【Nginx配置文件地址】
例如:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
② 三种关闭方式
从容停止 : Kill -QUIT 13421
快速停止 : kill -TERM 13421 或 kill -INT 13421
强制停止 : pkill -9 nginx
③ 重启
第一种reload命令:
[root@localhost local]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx -s reload
第二种发送信号方式:
kill -HUP 13421
至此Linux环境下 Nginx的安装配置以及启动停止都已经讲解完成了,这些过程最好自己动手实践一下哦。