Nginx专为性能优化而开发,其最知名的有点是它的稳定性和低系统资源消耗,以及对HTTP并发链接的高处理能力(单台物理服务器可支持30000~50000个并发请求)。正因如此,大量提供社交网络、新闻资讯、电子商务及虚拟主机等服务的企业纷纷选择Nginx来提供Web服务。html
RHEL6-5(IP地址为192.168.100.110)nginx
# yum -y install pcre-devel zlib-devel gcc gcc-c++
# useradd -M -s /sbin/nologin nginx //-M表示不让nginx在本地建立家目录,同时也禁止登陆到shell环境
# tar xzvf nginx-1.6.0.tar.gz -C /opt
# cd /opt/nginx-1.6.0/
./configure \
--prefix=/usr/local/nginx \ //安装目录
--user=nginx \ //指定用户
--group=nginx \ //指定组
--with-http_stub_status_module //开启stub_status状态统计模块c++
#make && make install #ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //让系统识别nginx命令
# nginx -t //检查 # nginx //启动 # killall -1 nginx //重启 # killall -3 nginx //中止
# vi /etc/init.d/nginx
#!/bin/bash # chkconfig: - 99 20 # description: Nginx Service Control Script PROG="/usr/local/nginx/sbin/nginx" PIDF="/usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0
# chmod +x /etc/init.d/nginx //给予执行权限 # chkconfig --add nginx //添加nginx服务项
# cd /usr/local/nginx/conf # mv nginx.conf nginx.conf.back //建立nginx的副本文件 # grep -v "#" nginx.conf.back > nginx.conf //去除#注释内容,方便管理 # vi nginx.conf //编辑nginx主配置文件
server { listen 80; server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } location ~ /status { //访问位置为/status stub_status on; //打开状态统计功能 access_log off; //关闭此位置的日志记录 } //在"server"这里插入的这4行的 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }