3tr21 发表于 2014-11-11 09:30:33

apache 配置文件详解

1、由于配置文件中的空行和注释很多所以要排除
    主配置文件:httpd.conf;( 注意备份)
   grep -Ev"#|^$"httpd.conf ;
    ServerRoot "/application/apache2.2.27"
    #服务的根目录;软件安装位置;
    Listen 80
    #web服务监听端口,用户访问使用;
    <IfModule !mpm_netware_module>
    <IfModule !mpm_winnt_module>
    #模块的开头
    User daemon
    Group daemon
    #每个进程都有用户,默认用户daemon(编译安装)
    </IfModule>
    </IfModule>
    ServerAdmin you@example.com
    #网站管理员的邮箱(当网站出问题时方便联系)
    DocumentRoot "/application/apache2.2.27/htdocs"
    #默认的站点目录
    <Directory />
    #权限控制;/表示根
          Options FollowSymLinks
          #可以带符号链接
          AllwOverride None
          #禁止相关的一些功能
          Order deny,allow
          Deny from all
          #不让任何人访问根目录
       </Directory>
      <Directory> "/application/apache2.2.27/htdocs"
#如果没有首页会展示目录结构
          Options Indexes FollowSymLinks
    # 优化 ,-Indexes 不对外展示目录结构
            AllwOverride None
            Order deny,allow
            Deny from all
      </Directory>
      报错403 找不到目录
    <IfModule dir_module>
      DirectoryIndex index.html
    #指定访问的首页;如果有多个用空格分开;
    </IfModule>
    <FilesMatch "^\.ht">
      Order allow,deny
      Deny from all
      Satisfy All
    </FilesMatch>
    ErrorLog "logs/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 "logs/access_log" common
    </IfModule>
    <IfModule alias_module>
      ScriptAlias /cgi-bin/ "/application/apache2.2.27/cgi-bin/"
    </IfModule>
    <IfModule cgid_module>
    </IfModule>
    <Directory "/application/apache2.2.27/cgi-bin">
    #cgi的配置 ,已不使用;
      AllowOverride None
      Options None
      Order allow,deny
      Allow from all
    </Directory>
    DefaultType text/plain
    #缺省的类型;
    <IfModule mime_module>
      TypesConfig conf/mime.types
      AddType application/x-compress .Z
      AddType application/x-gzip .gz .tgz
    #压缩控制
    </IfModule>
    <IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
    </IfModule>
2、扩展配置文件的信息(/conf/extra 路径)一般只了解;
    重点 :httpd-mpm.conf               
         httpd-vhosts.conf
         httpd-default.conf
    1)、 httpd-vhosts.conf    (需注意的地方)
      19 NameVirtualHost *:80 #端口配置
      27 <VirtualHost *:80>

             28   ServerAdmin webmaster@dummy-host.example.com
             29   DocumentRoot "/application/apache2.2.27/docs/dummy-host.example.com"
             30   ServerName dummy-host.example.com
             31   ServerAlias www.dummy-host.example.com
             32   ErrorLog "logs/dummy-host.example.com-error_log"
             33   CustomLog "logs/dummy-host.example.com-access_log" common
             34 </VirtualHost>
            #虚拟主机的配置;
-------------------------------------------------------------------------------------------
    2)、httpd-mpm.conf      锁文件;
         36 <IfModule mpm_prefork_module> #工作模式(常见的work和prefork模式);编译安装时没有指定工作模式,默认是prefork模式;
         37   StartServers          5
         38   MinSpareServers       5
         39   MaxSpareServers      10
         40   MaxClients          150#并发
         41   MaxRequestsPerChild   0
         42 </IfModule>
   <IfModule mpm_worker_module>#工做模式(编译的时候指定工作模式--with-    mpm=worker)
         52   StartServers          2
         53   MaxClients          150
         54   MinSpareThreads      25
         55   MaxSpareThreads      75
         56   ThreadsPerChild      25
         57   MaxRequestsPerChild   0
         58 </IfModule>

-------------------------------------------------------------------------------------------
    3)、httpd-default.conf 包括超时参数
      使用命令:cat -n httpd-default.conf| grep -v "#"

      10Timeout 300
      11# 连接超时
      16KeepAlive On
      17# 连接保持
      23MaxKeepAliveRequests 100
      24# 最大接受永久连接请求;
      29KeepAliveTimeout 5
      30      #在同一个连接等待下一个请求的时间
      38UseCanonicalName Off
      39# 伪静态相关,开发使用;
            (<Directory "/application/apache2.2.27/cgi-bin">
            AllowOverride None此处控制
      Options None)
      45AccessFileName .htaccess
      46
      55ServerTokens Full
      56#隐藏版本,跳整为Pord;
      65ServerSignature On
      66#控制不显示版本号,off关闭
      75HostnameLookups Off


页: [1]
查看完整版本: apache 配置文件详解