多语言展示
当前在线:218今日阅读:26今日分享:39

如何配置web服务器

Linux下配置web服务器
工具/原料

linux 系统

方法/步骤
1

1.1安装httpdd服务器1:准备工作vim /etc/sysconfig/network-scripts/ifcfg-eth0  //IP 地址配置DEVICE='eth0'HWADDR='00:0C:29:DB:7A:18'NM_CONTROLLED='yes'ONBOOT='yes'IPADDR=192.168.100.5NETMASK=255.255.255.0GATEWAY=192.168.100.254DNS1=192.168.100.5BOOTPROTO=staticvim /etc/sysconfig/networkvim /etc/sysconfig/selinuxSELINUX=disabledchkconfig iptables offservice iptables stop  //关闭防火墙vim /etc/yum.repos.d/iso.repo  //yum源安装[base]name=isobaseurl=file:///mnt/cdromenable=1gpgcheck=0mkdir /mnt/cdrommount /dev/cdrom /mnt/cdromecho '/dev/cdrom   /mnt/cdrom   defaults  0  0'>>/etc/fstab  //挂载光盘yum listyum install bind bind-chroot  //安装DNSvim /etc/named.conf   //全局配置文件listen-on port 53 { 192.168.100.5; };allow-query     { 192.168.100.0/24; };zone 'benet.com' IN {type  master;file 'benet.com.zone';};zone '100.168.192.in-addr.arpa' IN {type  master;file '192.168.100.arpa';};#cd /var/named/#vim benet.com.zone  //创建正向区域文件#vim 192.168.100.arpa  //创建反向区域文件[root@ns1 桌面]# cd /var/named[root@ns1 named]# named-checkzone benet.com benet.com.zone  //检查配置zone benet.com/IN: loaded serial 0OK[root@ns1 named]# chmod +r   benet.com.zone[root@ns1 named]# chmod +r   192.168.100.arpa[root@ns1 named]# chown :named benet.com.zone[root@ns1 named]# chown :named 192.168.100.arpa[root@ns1 named]# service named start[root@ns1 named]# chkconfig named on

2

2:安装httpd服务器[root@dns1 ~]# rpm -e httpd --nodeps  //卸载rpm方式安装的httpd服务器[root@dns1 ~]# cd /usr/tmp[root@dns1 tmp]# tar zxf httpd-2.2.17.tar.gz -C /usr/src  //解包[root@dns1 tmp]# cd /usr/src/httpd-2.2.17/[root@dns1 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi   //配置[root@dns1 httpd-2.2.17]# make  //编译及安装#make install

3

3:确认安装结果[root@dns1 httpd-2.2.17]# ls /usr/local/httpdbin    cgi-bin  error   icons    lib   man     modulesbuild  conf     htdocs  include  logs  manual4:优化执行路径[root@dns1 ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin[root@dns1 ~]# ls -l /usr/local/bin/httpd /usr/local/bin/apachectllrwxrwxrwx 1 root root 30  7月  8 10:27 /usr/local/bin/apachectl -> /usr/local/httpd/bin/apachectllrwxrwxrwx 1 root root 26  7月  8 10:27 /usr/local/bin/httpd -> /usr/local/httpd/bin/httpd例如:[root@dns1 ~]# httpd -vServer version: Apache/2.2.17 (Unix)Server built:   Jul  8 2017 10:21:235:添加httpd系统服务[root@dns1 ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd[root@dns1 ~]# vim /etc/init.d/httpd#!/bin/sh#chkconfig:35 85 21  // 服务识别参数,在级别3.5中启动;启动和关闭的顺序分别为85  21#description: startup script for the apache http service  //服务描述信息[root@dns1 ~]# chkconfig --add httpd  //将httpd添加为系统服务[root@dns1 ~]# chkconfig --list httpd // 查看httpd服务的自启动状态httpd           0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭

4

1.2 httpd服务器的基本配置web站点的部署过程1;确定网站名称及ip地址2;配置并启动httpd服务[root@dns1 ~]# vim /usr/local/httpd/conf/httpd.confServerName www.benet.com[root@dns1 ~]# /usr/local/httpd/bin/apachectl -tSyntax OK[root@dns1 ~]# /etc/init.d/httpd start[root@dns1 ~]# netstat -anpt | grep httpdtcp        0      0 :::80                       :::*                        LISTEN      93287/httpd3:部署网页文档[root@dns1 ~]# cat /usr/local/httpd/htdocs/index.html  //查看默认的网页

It works!

[root@dns1 ~]#[root@dns1 ~]# vim /usr/local/httpd/htdocs/index.html  //编辑网页4;在客户机上访问WEB站点5:查看WEB站点的访问情况[root@dns1 ~]# tail /usr/local/httpd/logs/access_log  //查看访问情况192.168.1.1 - - [08/Jul/2017:11:06:43 +0800] 'GET / HTTP/1.1' 200 45192.168.1.1 - - [08/Jul/2017:11:06:43 +0800] 'GET /favicon.ico HTTP/1.1' 404 209192.168.1.1 - - [08/Jul/2017:11:06:46 +0800] 'GET /favicon.ico HTTP/1.1' 404 209[root@dns1 ~]# tail /usr/local/httpd/logs/error_log  //查看错误的日志信息1.3:httpd .conf配置文件1全局配置1.4网站访问情况统计部署Awstats分析系统1:安装AWStats软件包[root@dns1 ~]# cd /usr/tmp[root@dns1 tmp]# tar zxf awstats-7.3.tar.gz[root@dns1 tmp]# mv awstats-7.3 /usr/local/awstats2:为需要统计的站点建立配置文件[root@dns1 tmp]# cd /usr/local/awstats/tools/[root@dns1 tools]# chmod +x awstats_configure.pl[root@dns1 tools]# ./awstats_configure.pl  //执行脚本1)指定http d主配置文件的路径> /usr/local/httpd/conf/httpd.conf2)设置日志类型Do you want me to setup Apache to write 'combined' log files [y/N] ? yfile (required if first install) [y/N] ? y    //确认创建新的站点配置文件3)为指定的web站点创建配置文件Your web site, virtual server or profile name:> www.benet.com     //指定要统计的目标网站名称4)后续工作按两次enter键退出3:修改站点统计配置文件[root@dns1 tools]# vim /etc/awstats/awstats.www.benet.com.confLogFile='/usr/local/httpd/logs/access_log'DirData='/var/lib/awstats'[root@dns1 tools]# mkdir /var/lib/awstats4:执行日志文件,并设置cron计划任务[root@dns1 tools]# chmod +x awstats_updateall.pl[root@dns1 tools]# ./awstats_updateall.pl now[root@dns1 tools]# crontab -e*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now[root@dns1 tools]# chkconfig --level 35 crond on5:访问awstats分析系统http://www.benet.com/awstats/awstats.pl?config=www.benet.com简化操作[root@dns1 tools]# vim /usr/local/httpd/htdocs/awb.htmlhttp://www.benet.com/awb.html~

推荐信息