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

[经验分享] linux下apache配置

[复制链接]

尚未签到

发表于 2018-11-22 12:11:30 | 显示全部楼层 |阅读模式
  Apache简介
  

  Apache源于NCSAhttpd服务器,经过多次修改,成为世界上最流行的Web服务器软件之一。Apache取自“a patchy server”的读音,意思是充满补丁的服务器,因为它是自由软件,所以不断有人来为它开发新的功能、新的特性、修改原来的缺陷。Apache的特点是简单、速度快、性能稳定,并可做代理服务器来使用。
  

  环境拓扑:
                                        LinuxClient
  ----------RHEL5.9(vmnet1)----------(vmnet1)
                                        Win7Client
  

  

  前提条件:
  1、配置IP
  [root@localhost ~]# cat/etc/sysconfig/network-
  scripts/ifcfg-eth0
  
  # Intel Corporation 82545EMGigabit Ethernet Controller
  (Copper)
  DEVICE=eth0
  BOOTPROTO=static
  ONBOOT=yes
  HWADDR=00:0c:29:5d:a8:80
  IPADDR=192.168.10.253
  NETMASK=255.255.255.0
  
  2、配置主机名
  [root@localhost ~]# cat/etc/sysconfig/network
  NETWORKING=yes
  NETWORKING_IPV6=yes
  HOSTNAME=web01.tarena.com
  3、修改hosts文件
  [root@localhost ~]# cat /etc/hosts
  # Do not remove the followingline, or various programs
  # that require networkfunctionality will fail.
  127.0.0.1               localhost.localdomain localhost
  ::1             localhost6.localdomain6 localhost6
  192.168.10.253  web01.tarena.com        web01
  
  
  实验一:查看默认HTTP配置
  找到默认红帽欢迎页面(/etc/httpd/conf/httpd.conf ---->Include ---->/etc/httpd/conf.d  ----> welcome.conf  ---->/var/www/error/noindex.html)
  
  4、软件包的安装
  [root@localhost ~]# rpm -qhttpd         
package httpd is not installed             //提示没有安装
  [root@localhost ~]# yum -yinstall httpd
  
  5、启动服务
  [root@localhost ~]# servicehttpd restart
  [root@localhost ~]# chkconfighttpd on
  
  
  试验二:基本HTTP服务器的配置
     Web服务器域名:www.tarena.com
     默认首页包括:index.html、index.php
     开启保持连接
     确认默认httpd是否支持php
     网站用老师提供的test_web.zip测试
  
  服务器操作:
  1、备份主配置文件
  [root@localhost ~]# cd/etc/httpd/conf
  [root@localhost conf]# cphttpd.conf httpd.conf.bak
  2、修改主配置文件
  [root@localhost ~]# vim/etc/httpd/conf/httpd.conf
  ...
   74 KeepAlive On     //是否保持连接,可选On或Off
  ...
  265 ServerName www.tarena.com:80      //设主机名
  ...
  391 DirectoryIndex index.htmlindex.php     //设默认首页
  ...
  3、启动服务
  [root@localhost ~]# servicehttpd restart
  [root@localhost ~]# cd/root/Desktop/
  [root@localhost Desktop]#unzip test_web.zip   //解压网站包(可以在网上找)
  [root@localhost Desktop]#mvjiajutiyan/* /var/www/html/  //导入到html下
  
  4、编写测试php页面
  [root@localhost ~]# cat/var/www/html/test.php
  
  
  测试:
  1、在客户端hosts文件指定
  C:\Windows\System32\drivers\etc(没有DNS服务,又想通过域名访问,只能写hosts文件
  192.168.10.253      www.tarena.com      www
DSC0000.jpg

  2、打开浏览器
  http://www.tarena.com
DSC0001.jpg

  http://www.tarena.com/test.php
  
DSC0002.jpg

  

  说明不支持PHP
  
  实验二 1.拒绝所有人访问,只允许192.168.10.21访问
         2.给一个长目录建立别名
  1.允许192.168.10.21访问
  [root@localhost ~]# vim/etc/httpd/conf/httpd.conf
  ...
  306
  ...
  333     Order allow,deny               //先允许,后拒绝
  334 #    Allow from all                //允许所有
  335     Allow from 192.168.10.21       //只允许21访问,其它拒绝
  336
  ...
  
  2、新建authdir站点
  [root@web01 ~]# mkdir/var/www/html/authdir
  [root@localhost ~]# cat -n/var/www/html/authdir/index.php
       1 www.tarena.com
  [root@web01 ~]# vim/etc/httpd/conf/httpd.conf
  ...
  337
  338         Order allow,deny
  339         Allow from all
  340
  [root@localhost ~]# servicehttpd restart
  在不同客户端测试
DSC0003.jpg

  
DSC0004.jpg

  

  
  
试验四:HTTP的用户授权
  客户端访问http://www.tarena.com/authdir需要输入用户名密码验证

1、修改主配置文件
[root@localhost~]# vim /etc/httpd/conf/httpd.conf
...
337
338         Order allow,deny
339         Allow from all
340         AuthName "Please InputPassword!!"  //认证领域名称,用于弹窗提示
341         AuthType Basic          //认证类型,一般使用basic
342         AuthUserFile"/etc/httpd/.vuser"   //用户数据文件的路径
343         Require valid-user      //指定授权用户或组
344
...
2、创建账户密码
[root@localhost~]# htpasswd -c /etc/httpd/.vuser  admin
New password:               //设置密码
Re-type newpassword:       //重置设置密码
Adding passwordfor user admin
3、启动服务测试
[root@localhost~]# service httpd restart
在不同客户端上测试
http://www.tarena.com/authdir
DSC0005.jpg


DSC0006.jpg



  
实验五:HTTP目录别名
客户端访问http://www.tarena.com/sina时可以访问/var/www/html/sina.com/bbs下的网页
1、创建测试站点
[root@localhost~]# mkdir -p /var/www/html/sina.com/bbs
[root@localhost~]# cat /var/www/html/sina.com/bbs/index.html
www.tarena.com
2、修改主配置文件
[root@localhost~]# tail -n 1 /etc/httpd/conf/httpd.conf
Alias      /sina    "/var/www/html/sina.com/bbs"      //设置别名
3、启动服务测试
[root@ser1 ~]#service httpd restart
http://www.tarena.com/sina

DSC0007.jpg



如果报错,请查看主配置权限
    Allow from all
#   allow from192.168.10.21

实验六:
  查看默认HTTP使用进程管理方式
  更改默认进程管理方式为worker模式
[root@localhost~]# httpd -l    //查看httpd启用模块
Compiledin modules:         
  core.c
  prefork.c                   //prefork模式
  http_core.c
  mod_so.c
[root@localhost~]# cd /usr/sbin/
[root@localhostsbin]# ls http*               //查看所有http
[root@localhostsbin]# mv httpd httpd.prefork
[root@localhostsbin]# mv httpd.worker httpd
[root@localhostsbin]# service httpd restart     //重启服务
[root@localhostsbin]# httpd -l
Compiled inmodules:
  core.c
  worker.c              //worker模式(高并发时使用)
  http_core.c
mod_so.c

试验七:
  部署Awstats统计Http访问日志
安装前准备:
awstats-7.1.tar.gz软件
1、安装软件(软件在/usr/src下)
[root@localhost~]# cd /usr/src/
[root@localhostsrc]# tar -zxvf awstats-7.1.tar.gz -C /usr/local/
[root@localhostsrc]# cd /usr/local/
[root@localhostlocal]# mv awstats-7.1/ awstats
[root@localhostlocal]# cd awstats/tools/
[root@localhosttools]# ./awstats_configure.pl
...
Config file path('none' to skip web server setup):
>/etc/httpd/conf/httpd.conf    //输入apache的主配置文件
...
-----> Need tocreate a new config file ?
Do you want me tobuild a new AWStats config/profile
file (required iffirst install) [y/N] ? y   //生成awstats的配置文件
...
Your web site,virtual server or profile name:
>www.tarena.com            //输入你的web服务器名字
...
Default:/etc/awstats
Directory path tostore config file(s) (Enter for default):
>
...
/usr/local/awstats/tools/awstats_updateall.plnow
Press ENTER tocontinue...
...
Press ENTER tofinish...
2、修改主配置文件
[root@localhosttools]# vim /etc/awstats/awstats.www.tarena.com.conf
...
  51LogFile="/var/log/httpd/access_log"
[root@localhosttools]# mkdir /var/lib/awstats   
3、将日志文件导入Awstats
[root@localhosttools]# ./awstats_updateall.pl now   //更新日志文件
[root@localhosttools]# crontab –l           //计划任务
*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
[root@localhosttools]# service crond restart
[root@localhosttools]# chkconfig crond on
4、验证:
http://www.tarena.com/awstats/awstats.pl?config=www.tarena.com

DSC0008.jpg



补充:
通过html代码实现网页跳转功能
[root@localhosttools]# cat /var/www/html/awstats.html






验证:
http://www.tarena.com/awstats.html







运维网声明 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-638223-1-1.html 上篇帖子: linux下apache服务搭建 下篇帖子: xampp启动Apache出错
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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