1 nginx基础知识1.1 nginx简介 Nginx("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。目前官方 Nginx 并不支持 Windows,只能在Linux、UNIX、BSD 系统下安装和使用。Nginx 本身只是一个 HTTP 和反向代理服务器,它无法像 Apache 一样通过安装各种模块来支持不同的页面脚本,例如 PHP、CGI 等。
1.2 nginx功能Nginx 支持简单的负载均衡和容错;支持作为基本 HTTP 服务器的功能,例如日志、压缩、Byte ranges、Chunked responses、SSL、虚拟主机等等,应有尽有。
2 nginx部署方法2.1 准备介质Nginx部署之前,首先根据项目的需要选择需要安装的组件,实际环境一般会考虑需要支持gzip压缩和rewrite模块。所以安装的第一步是下载Nginx及Nginx的相关组件。 2.2 安装步骤实际条件:RedHat 6.5 64bit 系统自带组件: zlib为:1.2.3版本 [iyunv@localhost ~]# rpm -qa zlib
pcre为:7.8版本 [iyunv@localhost ~]# rpm -qa pcre
上传nginx-0.8.55.tar.gz至文件夹/usr/local/src,并解压安装: [iyunv@localhost ~]# cd /usr/local/src [iyunv@localhost src]# ls [iyunv@localhost src]# tar zxvf nginx-0.8.55.tar.gz [iyunv@localhost src]# cd nginx-0.8.55 [iyunv@localhost nginx-0.8.55]# ./configure --prefix=/usr/local/nginx 报错:(猜测是因为pcre-7.8版本过高,nginx-0.8.55版本太低)
尝试安装高版本的nginx-1.6.2: [iyunv@localhost nginx-0.8.55]# cd .. [iyunv@localhost src]# ls [iyunv@localhost src]# tar zxvf nginx-1.6.2.tar.gz [iyunv@localhost src]# cd nginx-1.6.2 [iyunv@localhost nginx-1.6.2]# ./configure--prefix=/usr/local/nginx 依旧会出现该问题:
上网查资料,解决方法: 安装pcre-devel(对照操作系统版本去rpmfind.net下载或从光盘中获得 pcre-devel-7.8-6.el6.x86_64.rpm,并上传至/usr/local/src) [iyunv@localhost src]# ls [iyunv@localhost src]# rpm -ivh pcre-devel-7.8-6.el6.x86_64.rpm [iyunv@localhost src]# cd nginx-0.8.55 [iyunv@localhost nginx-0.8.55]# ./configure--prefix=/usr/local/nginx [iyunv@localhost src]# make
[iyunv@localhost nginx-0.8.55]# make install 2.3 管理nginx检查nginx配置文件:
[root@localhostnginx-0.8.55]# /usr/local/nginx/sbin/nginx –t
nginx启动及状态查看:
[root@localhostnginx-0.8.55]# /usr/local/nginx/sbin/nginx
[root@localhostnginx-0.8.55]# netstat -tunlp |grep nginx
查看nginx主进程号:
[root@localhostnginx-0.8.55]# ps -ef | grep "nginx: master process" | grep -v"grep" | awk -F ' ' '{print $2}'
停止nginx:
[iyunv@localhost nginx-0.8.55]# kill -TERM 26614 (主进程号) 或 [iyunv@localhost nginx-0.8.55]# /usr/local/nginx/sbin/nginx -sstop
重启nginx: [iyunv@localhost nginx-0.8.55]# /usr/local/nginx/sbin/nginx -s reload
配置开机自动启动nginx: [iyunv@localhost nginx-0.8.55]# vi /etc/rc.local
查看nginx 手动安装的模块: [iyunv@localhost nginx-0.8.55]# /usr/local/nginx/sbin/nginx –V
3 nginx升级步骤查看当前使用版本并记录之前编译的参数: [iyunv@localhost src]# /usr/local/nginx/sbin/nginx –V
按照之前编译的参数进行解压、编译,不用安装(make install): [iyunv@localhost src]# ls [iyunv@localhost src]# tar zxvf nginx-1.6.2.tar.gz [iyunv@localhost src]# cd nginx-1.6.2 [iyunv@localhost nginx-1.6.2]# ./configure--prefix=/usr/local/nginx
[iyunv@localhost nginx-1.6.2]# make
替换nginx文件: [iyunv@localhost nginx-1.6.2]# mv /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak20141231 [iyunv@localhost nginx-1.6.2]# find / -name nginx
[iyunv@localhost nginx-1.6.2]# cp objs/nginx/usr/local/nginx/sbin/nginx
测试新文件是否生效: [iyunv@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx –t
查看最新版本: [iyunv@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx –v
|