nginx安装【附件】

什么是Nginx?

Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。 

Nginx 作为 负载均衡 服务器: 

Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP 代理服务器对外进行服务。 Nginx 采用 C 进行编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好很多。作为邮件代理服务器: 

Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验。Nginx 是一个安装非常简单,配置文件非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。

Nginx的安装

模块依赖性Nginx需要依赖下面3个包

1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )

2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )

3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )

Nginx包下载: http://nginx.org/en/download.html

依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包.

图解教程

第一步: 下载安装所需包(请下载附件

openssl-fips-2.0.12.tar.gz

zlib-1.2.8.tar.gz

pcre-8.38.tar.gz

nginx-1.2.9.tar.gz

第二步:依次安装openssl-fips-2.0.12.tar.gz, zlib-1.2.8.tar.gz, pcre-8.38.tar.gz, nginx-1.2.9.tar.gz

1.安装openssl-fips-2.0.12.tar.gz

[root@localhost mrms]# tar -zxvf openssl-fips-2.0.12.tar.gz 

[root@localhost mrms]# cd openssl-fips-2.0.12

[root@localhost openssl-fips-2.0.12]# ./config 

[root@localhost openssl-fips-2.0.12]# make

[root@localhost openssl-fips-2.0.12]# make install

2.安装zlib-1.2.8.tar.gz

[root@localhost mrms]# tar -zxvf zlib-1.2.8.tar.gz

[root@localhost mrms]# cd zlib-1.2.8

[root@localhost zlib-1.2.8]# ./configure 

[root@localhost zlib-1.2.8]# make

[root@localhost zlib-1.2.8]# make install

3.安装pcre-8.83.tar.gz

[root@localhost mrms]# tar -zxvf pcre-8.38.tar.gz

[root@localhost mrms]# cd pcre-8.38
[root@localhost pcre-8.38]# ./configure 
[root@localhost pcre-8.38]# make
[root@localhost pcre-8.38]# make install

 4.安装 nginx-1.2.9.tar.gz

[root@localhost mrms]# tar -zxvf nginx-1.2.9.tar.gz 

[root@localhost mrms]# cd nginx-1.2.9

[root@localhost nginx-1.2.9]# ./configure --with-pcre=/opt/nginx/pcre-8.38 --with-zlib=/opt/nginx/zlib-1.2.8 --with-openssl=../openssl-fips-2.0.12

[root@localhost nginx-1.2.9]# make

[root@localhost nginx-1.2.9]# make install

至此Nginx的安装完成!

第三步:检测是否安装成功

[root@localhost nginx-1.2.6]# cd  /usr/local/nginx/sbin

[root@localhost sbin]# ./nginx -t

出现如下所示提示,表示安装成功

 

启动nginx

[root@localhost sbin]# ./nginx

查看端口

[root@localhost sbin]# netstat -ntlp

结果如下

推荐教程:http://blog.csdn.net/dyllove98/article/details/8892509

                  http://blog.csdn.net/shootyou/article/details/6093562/

nginx启动、重启、关闭

一、启动  

cd usr/local/nginx/sbin
./nginx

二、重启

  更改配置重启nginx  

kill -HUP 主进程号或进程号文件路径
或者使用
cd /usr/local/nginx/sbin
./nginx -s reload

    判断配置文件是否正确 

nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd  /usr/local/nginx/sbin
./nginx -t

-c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。     
-t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。 
-v 显示 nginx 的版本。   
-V 显示 nginx 的版本,编译器版本和配置参数。   
不启动,仅测试配置文件:/usr/bin/nginx -t -c ~/mynginx.conf  

三、关闭

  查询nginx主进程号

  ps -ef | grep nginx

  从容停止   kill -QUIT 主进程号

  快速停止   kill -TERM 主进程号

  强制停止   kill -9 nginx

  若nginx.conf配置了pid文件路径,如果没有,则在logs目录下

  kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

四、升级

  1、先用新程序替换旧程序文件

  2、kill -USR2 旧版程序的主进程号或者进程文件名

    此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行

  3、kill -WINCH 旧版本主进程号

  4、不重载配置启动新/旧工作进程

    kill -HUP 旧/新版本主进程号

    从容关闭旧/新进程

    kill -QUIT 旧/新进程号

    快速关闭旧/新进程

    kill -TERM 旧/新进程号

 

猜你喜欢

转载自zhongmin2012.iteye.com/blog/2317066