本文共 2423 字,大约阅读时间需要 8 分钟。
Nginx是一款相当优秀的用于部署动态网站的轻量级服务程序,它最初是为俄罗斯门户站点而开发的,因其稳定性、功能丰富、占用内存少且并发能力强而备受用户信赖。Nginx服务程序的稳定性源自于采用了分阶段的资源分配技术,降低了CPU与内存的占用率,所以使用Nginx程序部署的动态网站环境不仅十分稳定、高效,而且消耗的系统资源也很少。更重要的事,Nginx还支持热部署技术,可以7X24小时不间断提供服务,还可以在不暂停服务的情况下直接对Nginx服务程序进行升级。
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
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状态统计模块
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //让系统识别命令-----检查、启动、重启、停止--------nginx -t //检查nginx //启动killall -1 nginx //重启killall -3 nginx //停止
vi /etc/init.d/nginx
#!/bin/bash
#chkconfig: - 99 20#description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" instart)$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 1esacexit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
service nginx start
cd /usr/local/nginx/conf
mv nginx.conf nginx.conf.bak
grep -v "#" nginx.conf.bak > nginx.conf
vi nginx.confserver { 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; //关闭此位置的日志记录 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
nginx -t
service nginx restart
service iptables stop
setenforce 08.测试
转载于:https://blog.51cto.com/13620950/2136107