apache常用配置文件讲解

apache 的httpd.conf常用配置说明
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "/usr/local/httpd"
 
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80 (此处可以加其他的全局apache端口如 Listen 8080, 也可以在<VirtualHost> 之外添加某一个虚拟配置的监听端口)
 
LoadModule deflate_module modules/mod_deflate.so 启用压缩的模块
LoadModule expires_module modules/mod_expires.so 过期模块
LoadModule ssl_module modules/mod_ssl.so (https服务所需要的模块)
LoadModule vhost_alias_module modules/mod_vhost_alias.so  (虚拟配置重命名所需模块)
LoadModule alias_module modules/mod_alias.so (启用多域名所需模块)
LoadModule rewrite_module modules/mod_rewrite.so(重定向所需模块)
LoadModule php5_module    modules/libphp5.so (解析php文件所需模块)
 

 

<Directory />
    AllowOverride none
    Require all denied
</Directory>
这个配置改为以下配置比较通用
 <Directory />
     DirectoryIndex index.php
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
 </Directory>
 
DocumentRoot "/var/www/html"(默认文件根路径)
 
 
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
 
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None
 
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>
Directory 配置中建议改为
 DirectoryIndex index.php
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
比较通用
 
 
<IfModule dir_module>(默认路径的首次解析文件)
    DirectoryIndex index.php index.html
</IfModule>
 
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
以下两行为解析php所需添加的配置
AddType application/x-httpd-php .php
AddType application/x-httpd-php-sourece .phps
 
 
Include /etc/httpd/extra/httpd-vhosts.conf 引进虚拟配置文件
Include /etc/httpd/conf.d/*.conf  引进conf.d目录下的配置文件如ssl.conf文件
 
//设置过期时间的文件和gzip压缩相关参数
<IfModule mod_deflate.c>
DeflateCompressionLevel 5
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/javascript application/json
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/*
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
         ExpiresActive On
         ExpiresDefault A0
         <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
         ExpiresDefault A9030400
         </FilesMatch>
         <FilesMatch "\.(jpg|jpeg|png|gif|swf|js|css)$">
         ExpiresDefault A604800
         </FilesMatch>
</IfModule>
 
 
虚拟配置文件:
Listen 8080(添加某一个配置的监听端口)
<VirtualHost *:8080>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/var/www/html/wtsdata/app/web"
    ServerName test.wts.199.com
    ServerAlias alais.wts.test.199.com
   <Directory "/var/www/html/wtsdata/app/web">
     DirectoryIndex index.php
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>
 
    ErrorLog "logs/199-error_log"
    CustomLog "logs/199-access_log" common
</VirtualHost>
 
 

 

 

 

 

 

 
 
 

posted on 2017-02-15 14:50  Ryanyanglibin  阅读(1106)  评论(0编辑  收藏  举报

导航