设为首页 收藏本站
查看: 873|回复: 0

[经验分享] linux下搭建HTTP网站服务器和网站日志分析工具AWStats的使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-8-15 08:49:41 | 显示全部楼层 |阅读模式
服务器IP地址:192.168.4.5
服务器主机名:srv5.tarena.com
1.在服务器端安装httpd软件包
[iyunv@ser5 /]# yum -y install httpd
[iyunv@ser5 /]# service httpd start
[iyunv@ser5 /]# chkconfig httpd on
2.在客户机端验证
在浏览器中输入192.168.4.5
如果显示欢迎页面表示服务器搭建成功
3.部署网页文档
首先将欢迎页面配置移除
[iyunv@ser5 桌面]# cd /etc/httpd/conf.d/
[iyunv@ser5 conf.d]# mv welcome.conf welcome.conf.bak
建立测试主页
[iyunv@svr5 ~]# cd /var/www/html/
[iyunv@svr5 html]# vim index.html
Hello World!
浏览器验证
4.网站目录迁移和默认主页设置
[iyunv@ser5 html]# mkdir /var/ftp
[iyunv@ser5 html]# echo "wo shi ftp" > /var/ftp/index.html
[iyunv@ser5 html]# vim /etc/httpd/conf/httpd.conf
修改配置如下
DocumentRoot "/var/ftp"
将原来<Directory "/var/www/html">修改为<Directory "/var/ftp">
DirectoryIndex index.php index.html index.html.var
重新加载配置文件
[iyunv@ser5 html]# service httpd reload
浏览器验证
5.禁止使用符号链接和自动索引
[iyunv@ser5 ftp]# ln -s /var/www/html/index.html haha.html
浏览器输入验证http://192.168.4.5/haha.html
通过验证知道默认可以使用符号链接
下面禁用符号链接
[iyunv@ser5 ftp]# vim /etc/httpd/conf/httpd.conf
<Directory "目录路径">
     Options  -FollowSymlinks
     .. ..
</Directory>
[iyunv@svr5 ~]# service httpd restart
默认情况下主页不存在时访问网站会出现该目录的索引
[iyunv@ser5 ftp]# rm -rf index.html
浏览器验证出现索引
下面禁用自动索引
[iyunv@svr5 ~]# vim /etc/httpd/conf/httpd.conf
<Directory "目录路径">
     Options  -Indexes
     .. ..
</Directory>
[iyunv@svr5 ~]# service httpd restart
浏览器验证出现错误页面
6.使用目录别名
[iyunv@ser5 ftp]# echo "index" > /usr/src/index.html
[iyunv@ser5 ftp]# vim /etc/httpd/conf/httpd.conf
在文件末尾添加一行alias /tools "/usr/src/"
[iyunv@ser5 ftp]# service httpd reload
浏览器输入http://192.168.4.5/tools/能够访问服务器/usr/src/下的主页
7.客户机访问控制
允许从任何地址访问
<Directory  /var/www/html>
    Order  allow,deny
    Allow  from  all
</Directory>

仅允许从个别网段、IP地址访问
<Directory  /var/www/html>
    Order  allow,deny
    Allow  from  192.168.4.0/24  192.168.7.200
</Directory>
8.为指定目录启用用户授权
在网站根目录下建一个子目录test
能访问 http://服务器地址/test/
给studir添加用户授权,只允许用户stu01访问(密码123456)
新建主页和测试目录
[iyunv@ser5 ftp]# echo "Hello World" > index.html
[iyunv@ser5 ftp]# mkdir test
新建两个对test有权限的用户(不必是系统用户)
[iyunv@ser5 ftp]# htpasswd -c /etc/httpd/authpwd stu01
[iyunv@ser5 ftp]# htpasswd  /etc/httpd/authpwd stu02
[iyunv@ser5 ftp]# vim /etc/httpd/conf/httpd.conf
<Directory "/var/ftp/test">
    AuthName "Tarena Library."
    AuthType basic
    AuthUserFile /etc/httpd/authpwd
    #Require valid-user  //允许对test有权限的用户访问
    Require user stu01   //只允许stu01访问test目录  (和上面Require两个不能同时使    用)
</Directory>
[iyunv@ser5 ftp]# service httpd reload
浏览器输入http://192.168.4.5可以访问
输入http://192.168.4.5/test/需要输入账户和密码验证
9.构建AWStats日志分析系统
下载awstats工具
[iyunv@ser5 ~]# tar zxf awstats-7.1.tar.gz
[iyunv@ser5 ~]# mv awstats-7.1 /usr/local/awstats
[iyunv@ser5 ~]# cd /usr/local/awstats/tools/
[iyunv@ser5 tools]# ./awstats_configure.pl
> /etc/httpd/conf/httpd.conf (填写httpd的配置文件路径)
file (required if first install) [y/N] ? y
> srv5.tarena.com(填写做要日志分析的网站域名)
>
Press ENTER to continue...
> http://localhost(服务器名)/awstats/awstats.pl?config=srv5.tarena.com(网站域名)
//查看日志分析的网址
Press ENTER to finish...
修改awstats配置文件,指定要做日志分析的日志路径
[iyunv@ser5 tools]# vim /etc/awstats/awstats.srv5.tarena.com.conf
LogFile="/var/log/httpd/access_log" (指定日志路径)
创建日志分析出的数据指定目录
[iyunv@ser5 tools]# mkdir  /var/lib/awstats
执行日志分析,并设置cron计划任务
[iyunv@svr5 tools]# ./awstats_updateall.pl  now
.. ..
[iyunv@svr5 tools]# crontab  -e
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
查看分析结果
http://192.168.4.5/awstats/awstats.pl?config=srv5.tarena.com
为方便查看分析结果,可以将此超链接放到网站根目录的一个网页中
[iyunv@svr5 ~]# vim /网站根目录/aw-svr5.html
<html>  <head>
<meta http-equiv=refresh content="0;
url=http://服务器地址/awstats/awstats.pl?config=网站域名">
</head>
<body> </body>  </html>
访问http://服务器地址/aw-svr5.html
10.创建基于域名的虚拟主机
在没有配置DNS服务器的情况下通过修改/etc/hosts文件来实现客户机对服务器的域名解析
[ser5 /]# vim /etc/hosts (在服务器和客户端同时做这个步骤)
192.168.4.5 www.baidu.com www.google.com
创建两个虚拟主机的主目录和主页
[iyunv@ser5 /]# mkdir /var/www/baidu
[iyunv@ser5 /]# echo "baidu.com" > /var/www/baidu/index.html
[iyunv@ser5 /]# mkdir /var/www/google
[iyunv@ser5 /]# echo "google.com" > /var/www/google/index.html
创建虚拟主机的配置文件
[iyunv@ser5 /]# vim /etc/httpd/conf.d/Vhost.conf
NameVirtualHost 192.168.4.5
<VirtualHost 192.168.4.5>
        ServerName www.baidu.com
        DocumentRoot "/var/www/baidu"
</VirtualHost>
<VirtualHost 192.168.4.5>
        ServerName www.google.com
        DocumentRoot "/var/www/google"
</VirtualHost>
[iyunv@ser5 /]# service httpd reload
在客户机上分别输入www.baidu.com和[url=http://www.google.com]www.google.com[/url]
注:如果输入服务器IP地址,打开的是设置的第一个虚拟主机,因为当设置虚拟主机时,原来在httpd.conf中设置的网站将不能生效,如果想将原来在httpd.conf生效需要在虚拟主机配置文件修改如下
NameVirtualHost 192.168.4.5
<VirtualHost 192.168.4.5>
        ServerName 192.168.4.5
        DocumentRoot "/var/ftp"
</VirtualHost>
<VirtualHost 192.168.4.5>
        ServerName www.baidu.com
        DocumentRoot "/var/www/baidu"
</VirtualHost>
<VirtualHost 192.168.4.5>
        ServerName www.google.com
        DocumentRoot "/var/www/google"
</VirtualHost>
然后输入http://服务器IP 进行验证


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-23865-1-1.html 上篇帖子: linux分区工具fdisk的使用以及挂载设备 下篇帖子: linux下搭建samba服务器 服务器 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表