安装基础环境
准备一个nginx源码包
yum -y install pcre-devel zlib-devel gcc-c++
useradd -M -s /sbin/nologin nginx
tar xf nginx-1.12.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
直接输入nginx即可开启服务
nginx
yum -y install psmisc
killall -s HUP nginx
重启nginx服务
killall -s QUIT nginx
关闭nginx服务
vim /etc/init.d/nginx
添加nginx服务里面输入以下内容
#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Server Control Script
NP="/usr/local/nginx/sbin/nginx"
NPF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$NP;
if [ $? -eq 0 ]
then
echo "nginx is starting!! "
fi
;;
stop)
kill -s QUIT $(cat $NPF)
if [ $? -eq 0 ]
then
echo "nginx is stopping!! "
fi
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $NPF)
if [ $? -eq 0 ]
then
echo "nginx config file is reload! "
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
打开状态统计功能
vim /usr/local/nginx/conf/nginx.conf
在server中添加
location /status {
stub_status on;
access_log off;
}
重启服务
killall -s HUP nginx
192.168.254.11/status
ip/status
Active connections: 1 (活跃连接数)
server accepts handled requests (已经处理的连接信息)
1(已经处理的连接数) 1(成功的TCP握手次数) 1(已经处理的请求数)
Reading: 0 Writing: 1 Waiting: 0