华风 发表于 2019-1-30 08:54:11

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

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

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




页: [1]
查看完整版本: linux下搭建HTTP网站服务器和网站日志分析工具AWStats的使用