您的位置:首页 > 运维架构 > Apache

apache配置文件详解

2012-12-13 13:21 337 查看
/etc/apache/httpd.conf :

ServerRoot “/usr”

#因为安装到/usr下,所以ServerRoot是/usr。在以下配置中,以相对路径写的就是对于相对/usr

PidFile /var/run/httpd.pid

#httpd启动时的pid存放位置,用于start/stop apache

Timeout 300

#连接超时时间

KeepAlive On

#允许持续连接,一个连接多个请求.

MaxKeepAliveRequests 200

#持续连接中最大连接数,推荐大一些获得最佳性能

KeepAliveTimeout 15

#Client 在15秒内没有下次请求则断线

MinSpareServers 5

MaxSpareServers 10

httpd服务进程的数量,ps aux 可以看到

MaxClients 150

最大连接人数

Listen 80

#监听端口

#ExtendedStatus On

#使用/server-status查询服务器状态时给予完全信息(ON)或基本信息(OFF) 默认为OFF

User apache

Group apache

#httpd进程的user,group

ServerAdmin BlueSilence.xin@gmail.com

#admin的E-mail

ServerName 127.0.0.1

#服务器名称,需要是合法的DNS NAME 或者设置成IP

DocumentRoot “/srv/www/htdocs”

#主页存放目录

UserDir public_html

#每个用户的主页目录 (例如:/home/blue/public_html)

DirectoryIndex index.php index.html index.html.var

#当输入http://localhost 就会在主页根目录下搜索以上几个文件名做为首页显示

HostnameLookups Off

#记录log时,Client以主机名(On)或以IP(Off)记录,以IP记录更快些.

ErrorLog /var/log/apache/error_log

#错误日志位置

LogLevel warn

#日志记录等级,由信息多->少记录等级:debug, info, notice, warn, error, crit,alert,emerg

CustomLog /var/log/apache/access_log common

#访问日志位置

ServerTokens Prod

#当client访问到不存在的网页时提供信息的多少。少点好些


#由多–>少 :Full | OS | Minor | Minimal | Major | Prod

LanguagePriority zh-CN en ca cs da de ……….

#语言优先级

ErrorDocument 404 /missing.html

#错误网页处理,当出现404(找不到该页)则会显示/missing.html

目录设定:

设定根目录属性:

Options FollowSymLinks

AllowOverride None

Options 属性:

Indexes 当该目录下没有index.*时则以ftp-style列出该目录下所有文件

Includes Allow server-wide includes

FollowSymLinks 当该目录下软连接的文件/目录链接到外部目录时,仍然可以正常显示。

MultiViews 由一个*.var管理同一网页的多种语言版本,如apache默认主页多种语言的index.html

ExecCGI 允许执行CGI程序

ALL 开启除MultiViews之外的属性

None 禁止所有属性

AllowOverride 是否允许使用.htaccess覆盖某些设定(All None FileInfo AuthConfig Limit)

设定/srv/www/htdocs/ 目录(根目录)属性:

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

Order allow,deny : 控制访问权限

Order deny,allow

deny from test.org 拒绝test.org访问

deny from 192.168.0.100 拒绝192.168.0.100访问

allow from 192.168.0.1 允许192.168.0.1 访问

Alias /icons/ “/srv/www/icons/”

语法: Alias fakename realname

设置目录的别名,这样当输入http://localhost/icons/ 就可以访问到/srv/www/icons/

注意icons结尾的”/” 应在fakename realname 成对出现,要么全有,要么全没有.

有”/”时需要输入http://localhost/icons/ 才可以正常访问

ScriptAlias /cgi-bin/ “/srv/www/cgi-bin/”

设置可执行程序别名,与Alias类似。

当Client请求Alias realname时,server直接以document形式传送Client

而ScroptAlias则是server执行realname的script程序后将结果传送给Client

服务器的状态,信息:

通过http://localhost/server-status 访问

SetHandler server-status

Order deny,allow

Deny from all

Allow from 127.0.0.1

通过http://localhost/server-info 访问

SetHandler server-info

Order deny,allow

Deny from all

Allow from 127.0.0.1

.cgi .pl程序可执行的三种方法:

1:使用ScriptAlias,httpd.conf中加入:

ScriptAlias /my-cgi/ “/srv/www/cgi”

这样就可以以http://localhost/my-cgi/xxx.cgi xxx.pl执行/srv/www/cgi/下的.cgi,.pl程序了。

2: 使用sethandler cgi-scripts,httpd.conf中加入:

Alias /my-cgi/ “/srv/www/cgi”

Options ExecCGI

Sethandler cgi-script

3:使用Options的ExecCGI属性 :

将httpd.conf中的AddHandler cgi-script .cgi .pl 注释拿掉,加上.pl

给予/srv/www/cgi/ 执行CGI权限:

Alias /my-cgi/ “/srv/www/cgi”

Options ExecCGI

Allowoverride none

Order allow,deny

allow from all

认证网页:

Options FollowSymlinks Indexes ExecCGI

AllowOverride None

Order Allow,Deny

Allow From all

AuthName “private directory ”

AuthType Basic

AuthUserFile /etc/apace/apache.passwd

Require valid-user

AuthNmae : 认证窗口上的标题

AuthType : 认证类型,apache有几种认证方式,Basic为最基本的。

AuthUserFIle : 认证密码存放位置

Require : 认证档案中允许使用的用户

valid-user : 认证档案中所有的用户都可以使用通过认证进入该目录

如只想允许某个用户则使用 Require user username1 username2

建立认证密码文件:

#cd /etc/apache/

#htpasswd -c apache.passwd blue

New password:

Re-type new password:

Adding password for user blue

#

-c : 如果没有apache.passwd则创建它

增加认证用户:

#htpasswd apache.passwd silence

….

#apachectl restart

#firefox http://localhost/my-cgi/
要求密码才可以进入喽


.htaccess 和 allowoverride :

.htaccess : 取代httpd.conf中对.htaccess所在目录的设定。

AllowOverride :允许覆盖设定的类型(All None FileInfo AuthConfig Limit)

设定每个用户都可以建立自己的认证网页:

1.确定httpd.conf中AccessFileName .htaccess 没有被注释掉

2.编辑httpd.conf加入AllowOverride AuthConfig,允许每个用户通过.htaccess建立自己的认证网页

AllowOverride AuthConfig

Order Allow,Deny

Allow from all

3.用户建立认证目录,编写.htaccess :

mkdir private

cd private/

echo ” private page ” >test.html

vi .htaccess

AuthName “private”

AuthType basic

AuthUserFIle /home/blue/blue.passwd

Require valid-user

建立密码文件:

htpasswd -c blue.passwd blue

……

firefox http://localhost/~blue/private/test.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: