yt-summer 发表于 2017-12-25 17:56:19

03 编译安装apache的简易配置

  1.监听端口,默认为80,在主配置文件 /etc/httpd24/httpd.conf中可以更改

  2.持久连接
  

Include /etc/httpd24/extra/httpd-default.conf  

  主配置文件中取消该注释,并且到该文件中作相应具体修改
  

KeepAlive On  

#开启持久连接  
MaxKeepAliveRequests 100
  
#持久连接断开判断条件一,处理100个请求
  
KeepAliveTimeout 5
  
#条件二,超时5秒
  

  副作用,对并发访问量大的服务器,持久连接会使某些请求得不到相应,可以考虑使用时间较短的持久连接,apache2.4支持毫秒级的持久连接(有个疑问,怎么设置 可以设置成0.2 吗?)
  3.MPM
  可能用到的命令, (编译安装我切换工作模式,httpd -l 貌似显示不出来我静态编译的工作模式,rpm安装包可以显示),httpd -M可以查看当前加载模式
  在主配置文件中可以选择工作模式,这里我有个疑问,event模式去哪里了??有知道的大大麻烦指点下

  同时需要注释
  

# Server-pool management (MPM specific)  
Include /etc/httpd24/extra/httpd-mpm.conf
  prefork的配置:
  <IfModule prefork.c>
  StartServers       5  服务器启动时建立的子进程数量
  MinSpareServers    5  空闲子进程的最小数量
  MaxSpareServers   10  空闲子进程的最大数量
  ServerLimit   4000  服务器允许配置的进程数上限
  MaxClients      4000  最大请求数量,超过后进入等待队列,与以上保持一致,通称为内存M/2
  MaxRequestsPerChild4000  设置每个子进程在其生存期内最大请求数量,0为无限
  </IfModule>
  

  worker的配置:
  <IfModule worker.c>
  StartServers         5  启动时建立的子进程数量
  ServerLiMIT    20    服务器允许配置的进程数上限
  ThreadLimit       200   设置每个子进程可配置的线程数上限
  MaxClients         4000  请求最大线程数,超过进入等待队列
  MinSpareThreads   25  最小空闲线程数
  MaxSpareThreads   75  最大空闲线程数
  ThreadsPerChild   200  每个子进程的线程数
  MaxRequestsPerChild0  设置每个子进程在其生存周期内最大的请求数量,0为无限
  </IfModule>
  

  4.配置指令实现动态模块加载
  

LoadModule <mod_name> <mod_path>  

  5.文档页面路径
  

DocumentRoot "/var/www/html  

  同时注释
  

# Virtual hosts  
#Include /etc/httpd24/extra/httpd-vhosts.conf
  

  

  给文档路径以访问权限
  

DocumentRoot "/var/html"  
<Directory "/var/html">
  Options None
  AllowOverride None
  Require all granted
  
</Directory>
  

  ServerName暂改为 www.test.com
  在所在路径下建一个简单的html
  echo "Hello World" > /var/html/index.com
  添加hosts后可以访问了

  6. 日志设定

  日志定义设定
  

CustomLog logs/access_log combined  
LogFormat
"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  

  

%h:客户端IP地址;%l: Remote logname (from>
%u: Remote user,(from auth; may be bogus if return status (%s) is 401);  

%t:Time the request was received (standard english format),服务器收到请求的时间;  

%r:First line of request,请求报文的道行信息(method url version);  

%>s: 响应状态码;  

%b: 响应报文的大小,单位是字节,不包括响应报文首部;  

%{Referer}i:请求报文当中"referer"首部的值;当前资源的访问入口,即从哪个页面中的超链接跳转而来;%{User-Agent}i:请求报文当中"User-Agent"首部的值;即发出请求用到的应用程序;  

  对应的日志图片

  7.虚拟主机配置
  注释DocumentRoot ,启用vhost
  

# Virtual hosts  
Include /etc/httpd24/extra/httpd-vhosts.conf
  

  或者新加入自己设定的配置文件
  

# Virtual hosts  
#
Include /etc/httpd24/extra/httpd-vhosts.conf  
Include /etc/httpd24/vhosts
  

  <1>基于IP
  <2>基于端口
  <3>基于域名
  简单的基于域名的虚拟主机因该配置如下
  

<VirtualHost 172.16.0.87:80>  ServerName www.test01.com
  DocumentRoot
"/data/vhost/one"  

  
ErrorLog
/usr/local/apache24/logs/www.test01.com/Error_Log  
LogLevel warn
  

  

<IfModule log_config_module>  LogFormat
"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  LogFormat
"%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module>  LogFormat
"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio</IfModule>  CustomLog
"/usr/local/apache24/logs/www.test01.com/access_log" common  

</IfModule>  

  

  <Directory "/data/vhost/one/">
  Options None
  AllowOverride None
  Require all granted
  </Directory>
  
</VirtualHost>
  

  echo "Hello World!test01"   > /data/vhost/one
  echo "Hello World!test02"   > /data/vhost/two
  记得添加日志所需的目录
  测试如下
页: [1]
查看完整版本: 03 编译安装apache的简易配置