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

[经验分享] linux下apache服务搭建

[复制链接]

尚未签到

发表于 2018-11-22 12:09:35 | 显示全部楼层 |阅读模式
  实验拓扑:
                          Linux Client
-----RHEL5.9(vmnet1)----------(vmnet1)
                          Win7 Client

实验一:查看默认HTTP配置
     找到默认红帽欢迎页面
(/etc/httpd/conf/httpd.conf ---->Include ---->

/etc/httpd/conf.d  ----> welcome.conf  ---->

/var/www/error/noindex.html)  //通过主配置文件一步步查找到默认

页面
前提条件:
1,配置IP
[root@svr1 conf.d]# cat /etc/sysconfig/network-

scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller

(Copper)
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:DB:02:CE
ONBOOT=yes
IPADDR=192.168.1.254
NETMASK=255.255.255.0
2,主机名
[root@svr1 conf.d]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=svr1.tarena.com
GETEWAY=192.168.1.1
3,hosts文件
[root@svr1 conf.d]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1        localhost.localdomain localhost
::1        localhost6.localdomain6 localhost6
192.168.1.254    svr1.tarena.com svr1
[root@svr1 yum.repos.d]# yum -y install httpd    //安装
[root@svr1 ~]# vim /etc/httpd/conf/httpd.conf
Include conf.d/*.conf        //套用conf.d下以.conf结尾的配

置文件
[root@svr1 conf.d]# service httpd restart
[root@svr1 conf.d]# chkconfig httpd on        //启动服务
实验二:基本HTTP服务器的配置
     Web服务器域名:www.tarena.com
     默认首页包括:index.html、index.php
     开启保持连接
     确认默认httpd是否支持php   
     网站用老师提供的test_web.zip测试

服务器操作:
[root@localhost ~]# cd /etc/httpd/conf
[root@localhost conf]# cp httpd.conf httpd.conf.bak    //备份

主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf    //修改

参数
...
  74 KeepAlive On            //开启保持连接
...
265 ServerName www.tarena.com        //服务器域名
...
391 DirectoryIndex index.html index.php    //默认的首页文件
...
[root@localhost ~]# cd /root/Desktop/
[root@localhost Desktop]# unzip test_web.zip
[root@localhost Desktop]# mv jiajutiyan/* /var/www/html/   

//把测试页面放入网站默认的根路径/var/www/html
4、编写测试php页面
[root@localhost ~]# cat /var/www/html/test.php //写一个php测试

文档

测试:
[root@svr1 ~]# elinks http://www.tarena.com    //linux文本模

式下利用elinks可以测试网页可否访问
192.168.10.254    www.tarena.com    www    //在客户端指定hosts文


http://www.tarena.com        //会显示出/var/www/html下的网


http://www.tarena.com/test.php    //查看是否支持php,现在没有安装

php所以看到的是文档里写的字符


实验三:
只允许192.168.1.10访问http://www.tarena.com
允许所有用户访问http://www.tarena.com/authdir/index.html
[root@svr1 html]# vim /etc/httpd/conf/httpd.conf

     Order allow,deny    //认证规则allow,deny为先允许再拒绝,默认

拒绝所有;deny,allow为先拒绝在允许,默认允许所有
  #   Allow from all
     Allow from 192.168.1.10    //允许192.168.1.10访问

http://www.tarena.com


order allow,deny
allow from all            //允许所有访问

http://www.tarena.com/authdir/

[root@svr1 html]# mkdir -p /var/www/html/authdir
[root@svr1 html]# echo "aaaaa"

>/var/www/html/authdir/index.html
重启服务后分别在客户端测试结果应该为1.10可以访问上述两个站点,其

他客户机只能访问http://www.tarena.com/authdir/index.html

实验四:HTTP的用户授权客户端访问http://www.tarena.com/authdir需

要输入用户名密码 验证
1,修改主配置文件
[root@svr1 html]# vim /etc/httpd/conf/httpd.conf

order allow,deny
allow from all
authname "please input password!"    //用于弹窗提示
authtype "basic"            //认证类别,一般为basic
authuserfile "/etc/httpd/.passwd"    //认证用户文件
require valid-user            //指定授权用户或者组

valid-user为所有认证用户也可以写为user user1 user2 ...  group

组1 组2 ...

[root@svr1 html]# htpasswd -c /etc/httpd/.passwd user1   //创

建认证用户-c表示新建文件,在第一次创建的时候添加,之后再创建用户加

-c之前的用户会清空
New password:
Re-type new password:
Adding password for user user1
重启服务,在客户机测试
实验五:HTTP目录别名
客户端访问http://www.tarena.com/aa时可以访

问/var/www/html/aa/bb下的网页
1、创建测试站点
[root@svr1 html]# cd /var/www/html/
[root@svr1 html]# mkdir -p aa/bb/
[root@svr1 html]# echo "aaa" >aa/bb/index.html
2,修改配置文件
[root@svr1 html]# vim /etc/httpd/conf/httpd.conf
alias /aa /var/www/html/aa/bb
重启服务后在客户端测试

实验六:
     查看默认HTTP使用进程管理方式
     更改默认进程管理方式为worker模式
[root@svr1 bb]# httpd -l    查看httpd启用的模块
Compiled in modules:
   core.c
   prefork.c    //httpd默认的工作模式,比较稳定,但是占用的资源高
   http_core.c
   mod_so.c
把prefork模式改为worker模式
[root@svr1 bb]# cd /usr/sbin/
[root@svr1 sbin]# mv httpd httpd.prefork
[root@svr1 sbin]# mv httpd.worker httpd        //移动启动脚本
[root@svr1 sbin]# service httpd restart        //重启服务查看

效果
[root@svr1 sbin]# httpd -l
Compiled in modules:
   core.c
   worker.c        //发现启动模式改为了worker,worker处理高

并发的能力更强,但是不稳定
   http_core.c
   mod_so.c
     //prefork.c配置prefork模块
StartServers       8    //启动服务时开启8个进程
MinSpareServers    5    //最小空闲进程数,空闲进程不足5时建立新

的进程
MaxSpareServers   20    //最大空闲进程
ServerLimit      256    //进程限制为265以内
MaxClients       256    //最大进程数,不可大于serverlimit
MaxRequestsPerChild  4000    //最大请求

试验七:
     部署Awstats统计Http访问日志
1,解压安装
[root@svr1 ~]# tar zxf awstats-7.1.tar.gz -C /usr/src/
[root@svr1 ~]# cd /usr/src/
[root@svr1 src]# mv awstats-7.1/ /usr/local/awstats
[root@svr1 src]# cd /usr/local/awstats/   
[root@svr1 awstats]# ./tools/awstats_configure.pl  //配置脚本
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf        //httpd主配置文件路径
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y    //创建一个新配

置文件   
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.tarena.com    //域名
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>     //配置文件路径,默认,一路回车完成安装
[root@svr1 awstats]# mkdir -p /var/lib/awstats    //创建数据库文

件夹
[root@svr1 awstats]# vim

/etc/awstats/awstats.www.tarena.com.conf
LogFile="/var/log/httpd/access_log"    //修改httpd日志路径
[root@svr1 awstats]#

/usr/local/awstats/tools/awstats_updateall.pl now    //更新

日志文件
[root@svr1 awstats]# crontab -e    //添加计划任务,五分钟刷新一次
*/8 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
[root@svr1 awstats]# vim /var/www/html/awstats.html    //通过

html语言实现网页跳转功能






重启服务测试
在客户端修改hosts文件
192.168.1.254 www.tarena.com
然后通过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-638222-1-1.html 上篇帖子: Apache配置文件不完全翻译 下篇帖子: linux下apache配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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