<pre name="code" class="plain">
一、nginx简介
<pre name="code" class="plain">
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:京东、新浪、网易、腾讯、淘宝等。
Nginx 可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。Nginx 是一个很强大的高性能Web和反向代理服务器,它具有很多非常优越的特性:
在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应。Nginx作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可以支持作为 HTTP代理服务器对外进行服务。Nginx采用C进行编写,不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多。
二、nginx安装
nginx下载
cd /user/local
wget http://nginx.org/download/nginx-1.8.0.tar.gz
安装nginx依赖
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
解压缩nginx压缩包
tar -zxvf nginx-1.8.0.tar.gz
环境配置
cd nginx-1.8.0
./configure
编译安装
make && make install
常用命令
到此 nginx 已经安装完成,现在可以启动nginx了,一下是一些nginx启动加载命令和配置开机自启动cd /usr/local/nginx/sbin #进入到nginx命令目录
./nginx #启动nginx
ps -aux | grep nginx #查看nginx进程
./nginx -s stop<span style="white-space:pre"> </span> #关闭nginx
./nginx -s reload #重启nginx
./nginx -t #查看nginx状态
配置开机启动
cd /etc/init.d
touch nginx #在配置目录创建nginx文件
将一下内容粘贴到上边的nginx文件中
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
修改上述文件权限
chmod +x /etc/init.d/nginx
添加服务
chkconfig --add nginx
设置开机启动
chkconfig --level 35 nginx on
查看是否设置成功
chkconfig --list | grep nginx
此状态下表面开机启动成功