标签:start $1 chm tps 其他 user UI yum root
介绍Nginx是一款轻量级的HTTP服务器软件,由俄罗斯的Igor Sysoev开发。它能够支持高达50000个并发连接数的响应,拥有强大的静态资源处理能力,运行稳定,并且系统资源消耗非常低,现已逐渐被越来越多的用户认可,目前很多大型网站都应用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管理命令 ###########
nginx -t #nginx配置文件检查
nginx #启动
killall -1 nginx #重启nginx
killall -3 nginx #停止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
service nginx start
cd /usr/local/nginx/conf
mv nginx.conf nginx.conf.bak
grep -v "#" nginx.conf.bak > nginx.conf
vim nginx.conf
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; #关闭此位置的日志记录
}error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx -t
service nginx restart
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.web1.com; #域名
location / {
root /var/www/web1; #站点目录
index index.html index.php;
}
}server {
listen 80;
server_name www.web2.com; #域名
location / {
root /var/www/web2; #站点目录
index index.html index.php;
}
}
nginx -t
service nginx restart
访问www.web1.com 站点:
htpasswd -c /usr/local/nginx/passwd.db zhangsan
chmod 400 /usr/local/nginx/passwd.db
chown nginx /usr/local/nginx/passwd.db
vim /usr/local/nginx/conf/nginx.conf
location / {
auth_basic "secret"; #添加认证配置
auth_basic_user_file /usr/local/nginx/passwd.db; #指定密码文件路径
root html;
index index.html index.htm;
}
nginx -t
service nginx restart
vim /usr/local/nginx/conf/nginx.conf
location / {
deny 192.168.100.30; #禁止192.168.100.30访问
allow all; #允许其他主机访问
root html;
index index.html index.htm;
}
nginx -t
service nginx restart
未禁止访问时,该客户机可以正常访问浏览
添加禁止访问设置后,该客户机已经不能够访问浏览了
标签:start $1 chm tps 其他 user UI yum root
原文地址:http://blog.51cto.com/10316297/2130972