LNMP搭建
一、安装前准备
[root@localhost lnmp]# yum -y install pcre-devel zlib-devel
[root@localhost lnmp]# yum -y install gcc*
#nginx的配置的运行需要pcre、zlib等软件包支持;
[root@localhost lnmp]# useradd -M -s /sbin/nologin nginx
[root@localhost lnmp]# ls
mysql-5.1. SKYUC_3.2.2_Free_For_PHP5.3.tar.bz2
nginx-1.0. ZendGuardLoader-php-5.
php-5.3. ZendGuardLoader-php-5.3-linux-glibc23-x86_
[root@localhost lnmp]# tar -zxvf nginx-1.0.
[root@localhost lnmp]# cd nginx-1.0.8
[root@localhost nginx-1.0.8]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@localhost nginx-1.0.8]# make
[root@localhost nginx-1.0.8]# make install
[root@localhost nginx-1.0.8]# /usr/local/nginx/sbin/nginx
#启动服务
[root@localhost nginx-1.0.8]# netstat -antp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5986/nginx
#查看端口
网页访问:
Welcome to nginx!
关闭服务:
[root@localhost nginx-1.0.8]# kill -9 5986
[root@localhost nginx-1.0.8]# netstat -antp
#这种方法不可用,杀掉进程之后又重新生成进程;
[root@localhost nginx-1.0.8]# kill -s QUIT 5987
#特殊用法,可用关闭nginx
实现service管理nginx
所有service能够识别的启动脚本在:cd /etc/init.d/
/etc/inittab/
/etc/rc.d/rc*.d/ 对应的7种运行级别;
为源码包安装的nginx创建启动脚本
[root@localhost init.d]# vim nginx
#!/bin/bash
#descriotion: Nginx Server Scripts
#chkconfig: 2345 99 20
#优先级设置
a="/usr/local/nginx/sbin/nginx"
#启动命令;
b="/usr/local/nginx/logs/nginx.pid"
#pid文件存放位置;
case $1 in
start)
$a
echo "Nginx Server si starting! [确定]"
;;
stop)nginx和apache区别
kill -s QUIT $(cat $b)
echo "Nginx Server si stopping! [确定]"
;;
restart)
$0 stop &>/dev/null
$0 start &>/dev/null
echo "Nginx Server si restarting! [确定]"
;;
reload)
kill -s HUP $(cat $b)
echo "Nginx Server si reloading! [确定]"
#重新加载;
;;
*)
echo "error | start | stop | restart | reload"
esac
#pid文件,一般的都与日志存放在一起;
添加统计模块
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# f
加入以下行
48 location /tongji {
49 stub_status on;
50 }
[root@localhost conf]# service nginx restart
验证访问页面如下:
192.168.69.149/tongji
Active connections: 1
server accepts handled requests
1 1 45
Reading: 0 Writing: 1 Waiting: 0
如上图所示:其中"Active connections"表示当前的活动连接数;而"server accepts handled
requests"表示已经处理的连接信息,三个数字依次表示已处理的连接数、成功的TCP握手次
数、已处理的请求数.
控制访问统计模块(基于用户名密码)
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# f
51 auth_basic "welcome BJ";
52 auth_basic_user_file /usr/local/nginx/html/a.psd;
[root@localhost conf]# htpasswd -c /usr/local/nginx/html/a.psd zhangsan
#创建配置文件里指定的密码文件;htpasswd -c生成密码文件;
New password: 123
Re-type new password: 123
Adding password for user zhangsan
[root@localhost conf]#
[root@localhost conf]# service nginx restart
Nginx Server si restarting! [确定]
浏览器访问如下:
控制访问统计模块(客户端地址访问控制)
54 allow 192.168.69.49;允许这个
55 deny 192.168.0。0/24;拒绝这些?
注:allow 允许规则,deny拒绝规则;规则的执行是按从上向下执行,匹配某条规则后将不
再检查其他规则。
一、虚拟主机
1.基于端口
2.IP
3.域名
准备DNS服务器
234 yum -y install bind
235 vim /f
236 vim /etc/s
237 cd /var/named/
238 ls
239 cp -p named.localhost ylk.localhost
240 vim ylk.localhost
241 cp -p xdl.localhost xjj.localhost
242 vim xjj.localhost
243 service named start
[root@localhost named]# service named restart
停止 named: [确定]
Generating /etc/rndc.key:
#卡在这里,解决如下;
[root@localhost named]# rndc-confgen -r /dev/urandom -a
wrote key file "/etc/rndc.key"
[root@localhost named]# service named restart
停止 named:. [确定]
启动 named: [确定]
启动成功;
[root@localhost conf]# f
复制35-56行 粘贴,之后修改如下:
37 server_name www.xdl;
44 root html/xdl;
##指定目录
59 server_name www.y05;
66 root html/y05;
#指定目录
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# mkdir xdl y05
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论