Nginx安装部署

Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器,其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。

1、安装PCRE库

下载地址:http://www.pcre.org/

tar -jxvf  pcre-8.36.tar.bz2

cd pcre-8.36

./configure

make

make install

2、安装zlib库

下载地址:http://zlib.net/

tar -zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make

make install

3、安装ssl

下载地址:http://www.openssl.org/

tar -zxvf openssl-1.0.2d.tar.gz

cd openssl-1.0.2d

./config

make

make install

备注:pcre为了重写rewrite,zlib为了gzip压缩,openssl是https访问所需

4、安装nginx

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,安装Nginx到 /usr/local/nginx 目录下。

./configure --sbin-path=/usr/local/nginx/nginx--conf-path=/usr/local/nginx/nginx.conf

--pid-path=/usr/loacal/nginx/nginx.pid

--with-http_ssl_module

--with-http_realip_module

--with-http_sub_module

--with-http_gunzip_module 

--with-http_gzip_static_module

--with-http_stub_status_module

--with-openssl=../openssl-1.0.2d

--with-pcre=../pcre-8.36

--with-zlib=../zlib-1.2.8

make

make install

5.启动nginx

进入到nginx安装目录/usr/local/nginx下,执行

[root@jason1~]# cd /usr/local/nginx/

[root@jason1nginx]# ./nginx

[root@jason1nginx]# ps -ef|grep nginx

root     17577    1  0 22:47 ?        00:00:00 nginx: master process ./nginx

nobody   17578 17577 0 22:47 ?        00:00:00 nginx:worker process

root     17580 3591  0 22:48 pts/1    00:00:00 grep nginx

[root@jason1nginx]#

通过访问web页面查看,显示如下结果

wKioL1ZMM7mQffLmAAGMT-9jRwk950.jpg

Nginx安装部署成功。

6、Nginx常用管理命令行参数。

[root@jason1nginx]# ./nginx -h

nginxversion: nginx/1.4.7

Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:

  -?,-h        : this help

  -v           : show version and exit

  -V           : show version and configure options then exit

  -t           : test configuration and exit

  -q           : suppress non-error messages during configuration testing

  -s signal    : send signal to a master process: stop, quit, reopen, reload

  -p prefix    : set prefix path (default: /usr/local/nginx/)

  -c filename  : set configuration file (default: /usr/local/nginx/nginx.conf)

  -g directives : set global directives out ofconfiguration file

 

stop — shut down quickly

quit — shut down gracefully

reload — reload configuration, start thenew worker process with a new configuration, gracefully shut down old workerprocesses.

reopen — reopen log files

 

Nginx启动

/usr/local/nginx/nginx

 

Nginx关闭

/usr/local/nginx/nginx -s stop

/usr/local/nginx/nginx -s quit

 

Nginx重新加载配置文件

/usr/local/nginx/nginx -s reload

 

Nginx测试配置文件语法是否正确

/usr/local/nginx/nginx -t -c /usr/local/nginx/nginx.conf