前提已安装好DNS
安装:yum -y install httpd
开放80端口:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
目录:/etc/httpd/conf/httpd.conf #配置文件目录
/etc/httpd/conf.d/ #引用配置目录
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html" #网页文件目录
<Directory "/var/www/html"> #目录设置
options Indexes FollowSymLinks 当有Indexes时,当主目录下没有index.html文件时,允 许查看目录列表!去掉可以删掉或:-Indexes
AllowOverride None #None不查找.htaccess文件
Order allow,deny #Order 控制访问,最后deny才是默认
Allow from all # 用法deny ip1 ip2
</Directory>
启用AllowOverride方法
mkdir /var/www/html/yy/
echo "yy">/var/www/html/yy/index.html
创建.htaccess文件
cd /var/www/html/yy
vim .htaccess
AuthName isyy
AuthType basic
Authuserfile /var/www/html/.htaccess
require
保存
加入用户ltiaw
htpasswd -cm .htaccess ltiaw
定义目录
<Directory "/var/www/html/yy/">
Options Indexes Followsymlinks
AllowOverride AuthConfig
Order deny,allow
Allow from 127.0.0.1
Deny from all
</Directory>
这样就启用了用户验证
如果访问不了,注意是不是selinux 或文件权限问题
用软链接把在别的目录下的index.html链接到/var/www/html/目录下使用
mkdir /xx
echo "xx" >/xx/index.html
ln -s /xx/index.html /var/www/html/
自定义目录
Alias /aa/ "/aa/"
mkdir /aa
echo "aa">/aa/index.html
chcon -R --reference=/var/www/html/ /aa/
scriptAlias /cgi-bin/ "/var/www/cgi-bin" #定义可执行脚本的目录
cd /var/www/cgi-bin/
创建脚本
vim text.sh
#!/bin/bash/
echo $date
保存
chmod 755 ./text.sh
访问刷新
虚拟主机
NameVirtualHost
搭DNS建立3个zone
分别是
baidu.com
google.com
ltiaw.com
第一种基于主机名的虚拟主机
去掉注释NameVirtualHost*:80
定义主机名
<VirtualHost*:80>
DocumentRoot /baidu
servername www.baidu.com
</VirtualHost>
<VirtualHost*:80>
DocumentRoot /google
servername www.google.com
</VirtualHost>
<VirtualHost*:80>
DocumentRoot /var/www/html/
servername www.ltiaw.com
</VirtualHost>
chcon -R --reference=/var/www/html/ /baidu /google
/etc/init.d/httpd restart
访问成功
第二种基于IP地址的虚拟主机
ip addr show eth0
ip addr add 192.168.30.251/24 dev eth0 label eth0:0
ip addr add 192.168.30.252/24 dev eth0 label eth0:1
ip addr show eth0
vim httpd.conf
注释NameVirtualHost*:80
定义IP
<VirtualHost 192.168.30.251:80>
DocumentRoot /baidu
servername www.baidu.com
</VirtualHost>
<VirtualHost 192.168.30.252:80>
DocumentRoot /google
servername www.google.com
</VirtualHost>
<VirtualHost 192.168.30.250:80>
DocumentRoot /var/www/html/
servername www.ltiaw.com
</VirtualHost>
/etc/init.d/httpd restart
成功访问
https 加密
yum -y install mod_ssl
cd /etc/httpd/conf.d
vim ssl.conf
SSLEngin on #开启SSL
定义证书目录
SSLCertificateFile /etc/httpd/conf/bb.crt
SSLCertificateKeyFile /etc/httpd/conf/bb.key
保存
生成证书
cd /etc/pki/tls/certs
make bb.crt
生成完成后复到conf目录下
cp bb.* /etc/httpd/conf
/etc/init.d/httpd restart
访问成功
只给一个站用SSl加密
vim /etc/httpd/conf.d/ssl.conf
SSLEngin off 关闭
vim /etc/httpd/conf/httpd.conf
在要启用的虚拟主机下加入
<VirtualHost 192.168.30.250:80>
DocumentRoot /var/www/html/
servername www.ltiaw.com
SSLEngin on
SSLCertificateFile /etc/httpd/conf/bb.crt
SSLCertificateKeyFile /etc/httpd/conf/bb.key
</VirtualHost>
/etc/init.d/httpd restart
日志监控
yum -y install webalizer
vim /etc/httpd/conf.d/webalizer.conf
改allow all
执行命令生成数据
webalizer
restart
另一个比较好看的工具
awstats-7.4-1.noarch.rpm
下载地址:
https://sourceforge.net/projects/awstats/files/AWStats/7.4/awstats-7.4-1.noarch.rpm/download
yum -y localinstall awstats-7.4-1.noarch.rpm
配置
执行:
perl /usr/local/awstats/tools/awstats_configure.pl
安装成功后显示!
A SIMPLE config file has been created: /etc/awstats/awstats.ltiaw.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘ltiaw.com‘ with command:
> perl awstats.pl -update -config=ltiaw.com #更新数据命令
You can also read your statistics for ‘ltiaw.com‘ with URL:
> http://localhost/awstats/awstats.pl?config=ltiaw.com #访问网址
ab 测试
ab -n 1000 -c 10 http://www.baidu.com/index.html/ #-n 1000次访问,-c 10个并行客户端
原文地址:http://xliunx.blog.51cto.com/1391404/1752126