Apache主配置文件内容详解
(一)基本配置
ServerRoot"/usr/local/apache2" //服务目录
Listen 80 //监听的ip地址、端口号
#LoadModule...... //启动时加载的模块
LoadModule deflate_modulemodules/mod_deflate.so
LoadModule expires_modulemodules/mod_expires.so
LoadModule rewrite_modulemodules/mod_rewrite.so
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon //运行服务的用户身份
Group daemon //运行服务的组身份
</IfModule>
</IfModule>
ServerAdmin you@example.com
ServerName localhost:80 //网站服务器域名
DocumentRoot"/usr/local/apache2/htdocs" //网页文档的根目录
#配置虚拟主机
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90:80>
DocumentRoot/home/httpd/html1
ServerNamewww.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_logcombined
</VirtualHost>
#下面是对根目录的一个权限设置
<Directory />
Options FollowSymLinks
Order deny,allow //对页面的访问控制顺序,后面的一项是默认选项,故此配置默认是allow
Deny from all
</Directory>
<Directory"/usr/local/apache2/htdocs">
AllowOverride None
Order allow,deny
Allow from all //表示允许所有的用户,通过和上一项结合可以控制对网站的访问控制
</Directory>
<IfModule dir_module>
DirectoryIndex index.html //默认的索引页文件,还可以添加index.php、index.htm等
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog "logs/error_log" //错误日志文件
LogLevel warn //记录日志的级别,默认为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/ "/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache2/cgi-bin">
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>
(二)虚拟主机
(注:以创建两个虚拟主机wgmml和rsysxx为例。)
1、基于域名的虚拟主机:使用不同的域名
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
NameVirtualHost10.1.4.90
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/www.rsysxx.com.access1_logcommon
</VirtualHost>
2、基于ip的虚拟主机:使用不同的ip
<VirtualHost 10.1.4.90>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
<VirtualHost 10.1.2.73>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/www.rsysxx.com.access1_logcommon
</VirtualHost>
3、基于端口的虚拟主机:使用不同的端口
Listen10.1.2.73:80
Listen10.1.2.73:8080
<VirtualHost 10.1.2.73:80>
DocumentRoot/user/local/apache2/htdocs/wgmml
ServerNamewww.wgmml.com
ErrorLog /usr/local/apache/logs/www.wgmml.com .error1_log
CustomLog /usr/local/apache/logs/www.wgmml.com.access1_logcommon
</VirtualHost>
<VirtualHost 10.1.2.73:8080>
DocumentRoot/user/local/apache2/htdocs/reysxx
ServerNamewww.rsysxx.com
ErrorLog /usr/local/apache/logs/www.rsysxx.com .error1_log
CustomLog /usr/local/apache/logs/ www.rsysxx.com.access1_logcommon
</VirtualHost>
(三)其他全局配置参数
LogLevel:记录日志的级别,默认为warn
Timeout 300:网络连接超时,默认为300秒
KeepAlive:是否保持连接,可选On或Off
MaxKeepAliveRequests100:每次连接最多请求文件数,0表示无限次
KeepAliveTimeout15:保持连接状态时的超时时间,超过时间自动断开
转载于:https://blog.51cto.com/wgmml/1242214