您的位置:首页 > 运维架构 > Nginx

linux 安装nginx

2017-12-19 16:38 741 查看

一、准备

用“rpm -qa | grep xxx” 命令查看是否已安装

需要查看的:pcre、openssl、gzip、wget、zlib

[linux@localhost Desktop]$ rpm -qa | grep "pcre"
pcre-devel-7.8-7.el6.x86_64
pcre-7.8-7.el6.x86_64
[linux@localhost Desktop]$ rpm -qa | grep openssl
openssl098e-0.9.8e-20.el6.centos.1.x86_64
openssl-1.0.1e-15.el6.x86_64
[linux@localhost Desktop]$ rpm -qa | grep gzip
gzip-1.3.12-19.el6_4.x86_64
[linux@localhost Desktop]$ rpm -qa | grep wget
wget-1.12-1.8.el6.x86_64
[linux@localhost Desktop]$ rpm -qa | grep zlib
zlib-1.2.3-29.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64


好的 以上可以看到都已经安装了

如果没有安装则使用yum命令安装下,需要在root权限下操作

分别是

yum install pcre*
yum install openssl*
yum install wget
yum install zlib
yum install zlib-devel


二、安装 ##

下面开始安装nginx

[root@localhost Desktop]# cd /usr/local/src
[root@localhost src]# wget http://nginx.org/download/nginx-1.8.0.tar.gz [root@localhost src]# tar -zxvf nginx-1.8.0.tar.gz
[root@localhost src]# cd nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx-1.8.0 \--with-http_ssl_module --with-http_spdy_module \--with-http_stub_status_module --with-pcre
[root@localhost nginx-1.8.0]# make
[root@localhost nginx-1.8.0]# make install


问题

./configure时报错:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.


解决办法:

yum -y install openssl openssl-devel


执行yum后查看下:

[root@localhost nginx-1.8.0]# rpm -qa | grep openssl
openssl-1.0.1e-57.el6.x86_64
openssl098e-0.9.8e-20.el6.centos.1.x86_64
openssl-devel-1.0.1e-57.el6.x86_64


再次执行./configure成功

参考:http://blog.csdn.net/testcs_dn/article/details/51461999

三、启动

进入安装目录 cd /usr/local/nginx-1.8.0

启动 ./sbin/nginx

查看服务是否启动ps -ef | grep nginx

[root@localhost local]# cd /usr/local/nginx-1.8.0
[root@localhost nginx-1.8.0]# ./sbin/nginx
[root@localhost nginx-1.8.0]# ps -ef | grep nginx
root       6103      1  0 08:31 ?        00:00:00 nginx: master process ./sbin/nginx
nobody     6104   6103  0 08:31 ?        00:00:00 nginx: worker process
root       6106   2768  0 08:31 pts/0    00:00:00 grep nginx


至此 安装完毕了。

修改conf/nginx.conf 来完成配置

之后 重启nginx 服务 即可

./sbin/nginx -s reload


以下操作参考:https://www.cnblogs.com/fhen/p/5896105.html

四、停止

停止操作是通过向nginx进程发送信号来进行的

步骤1:查询nginx主进程号

ps -ef | grep nginx


步骤2:发送信号

从容停止Nginx:
kill -QUIT 主进程号
例如:kill -QUIT 16391

快速停止Nginx:
kill -TERM 主进程号

强制停止Nginx:
kill -9 主进程号


五、平滑重启

如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。

平滑重启命令:

kill -HUP 住进称号或进程号文件路径
或者使用
/usr/nginx/sbin/nginx -s reload


注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:

nginx -t -c /usr/nginx/conf/nginx.conf
或者
/usr/nginx/sbin/nginx -t
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: