apache配置文件分析

安装apache并启动

[root@gaosh-64 ~]# yum install httpd
[root@gaosh-64 ~]# systemctl restart httpd
[root@gaosh-64 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  • 1
  • 2
  • 3
  • 4

常见配置及参数

vim /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd"			#用于指定Apache运行的根目录
Listen 80						#监听80端口
MaxClients  256					#指定同时能访问服务器的客户机数量为256
DocumentRoot "/var/www/html"	#网页文件存放的目录
DirectoryIndex index.html index.html.var	#默认网站主页
Include conf.d/*.conf			#读取/etc/httpd/conf/conf.d/目录中所有以.conf结尾的文件
ServerName www.wg.com			#域名
ServerAdmin						#设置管理员的邮箱
Include conf.d/*.conf			#包含的子配置文件
User apache						#用户是apache
Group apache					#用户组是apache
Directory 						#认证授权和访问控制


##################################
<IfModule prefork.c>     #当httpd服务使用的profork模型的时候:
 StartServers      10    #默认启动10个作业进程
 MinSpareServers    10    #空闲进程数不低于10个
 MaxSpareServers    20    #空闲进程数最大20个
 ServerLimit      256    #最多可以启动256个进程
 MaxClients       256    #最大并发客户端数为256个
 MaxRequestsPerChild 4000 #每个进程可以处理4000个请求,超过此数目进程被杀死并重新创建
</IfModule>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

需要注意的是:ServerLimit最大值为20000个,并且:由于profork是单一线程的进程,所以每个进程在同一时间里仅能处理一个请求(也就是一个请求一个进程),所以MaxClients的值要和ServerLimit一致。而且,profork的开销比较大,不过稳定性比较强。

使用案例:

搭建一台测试web服务器

要求如下:

  1. 首页为index.html,访问时候显示为“大家好,我是高胜寒,我正在设置测试机”
  2. 管理员的Email地址为:gaosh@yeah.net
  3. 网页编码采用UTF-8
  4. 所有网页均存放在 /var/www/html/目录下
  5. apache的配置文件根目录设置为/etc/httpd目录

注: 这里有很多都是默认的,我们来看一下如何配置。

切记: 修改配置文件前一定要备份

1. 备份配置文件

[root@gaosh-64 ~]# cp /etc/httpd/conf/httpd.conf httpd.bak

  • 1
  • 2

2. 修改配置文件

[root@gaosh-64 ~]# vim /etc/httpd/conf/httpd.conf

31  ServerRoot "/etc/httpd"  	#apache配置文件的根目录
32  Timeout 60  		#添加此项,超时时间  
42  Listen 80   	#监听的端口
  • 1
  • 2
  • 3

改:86 ServerAdmin root@localhost
为:86 ServerAdmin gaosh@yeah.net #设置管理员,e-mail 地址

改:95 #ServerName www.example.com:80
为:95 ServerName 192.168.1.64:80 #服务器主机名
119 DocumentRoot “/var/www/html” #网站页面根目录
144 Options Indexes FollowSymLinks #当一个目录没有默认首页时,允许显示此目录列表
改:164 DirectoryIndex index.html
为:164 DirectoryIndex index.html index.php #指定默认首页
316 AddDefaultCharset UTF-8 #设置服务器的默认编码为: UTF-8

3. 取消apache默认欢迎页

给文件加#号, 我这里使用的是ctrl +v --I --#–两下ECS
还记得这个方法吗? 看图:

[root@gaosh-64 ~]# vim /etc/httpd/conf.d/welcome.conf
在这里插入图片描述

4. 修改网页内容(index.html)

[root@gaosh-64 ~]# cat /var/www/html/index.html
大家好,我叫高胜寒,我正在设置测试页面
[root@gaosh-64 ~]#

5. 启动并测试

在这里插入图片描述

[root@gaosh-64 ~]# curl 192.168.1.64
大家好,我叫高胜寒,我正在设置测试页面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值