httpserver:在Windows下安装功能强大的Apache服务器端Web软件

38 views
Skip to first unread message

zhangfan xu

unread,
Sep 20, 2006, 5:05:05 AM9/20/06
to Technology_DB
一、软件简介

1.Apache是最流行的Web服务器端软件之一。快速、可靠、可通过简单的
API扩展,Perl/Python解释器可被编译到服务器中,完全免费,完全源代码开放。如果你需要创建一个每天有数百万人访问的Web服务器,Apache可能是最佳选择。


2.Apache Web Server
Win32从版本1.3.17开始使用MSI(扩展名)的形式发布,MSI文件可以在Windows下直接运行,使用起来就和我们平常所用的那些EXE(扩展名)文件一样的方便。


3.不过MSI文件这种新兴的东东也给使用微软较早发行的Win98和WinNT的用户带来了麻烦,当它们安装时系统会提示"无法通过Windows
安装程序服务安装此安装程序包。您必须安装带有更新版本Windows
安装程序服务的Windows Service
Pack",根本无法让你继续下去!--而在WinME和Win2K下面则不会有这种麻烦出现。


4.要解决在Win98和WinNT下安装MSI文件不能完成的麻烦,你需要先有相应版本的名为"Microsoft
Installer"的软件包,把它安装之后方可以开始MSI的安装工作。

5.本文所需相关文件在光盘中的路径如下所示:

(1)Apache HTTP Server Version
1.3:http://www.enanshan.com/down/apache_132.msi(2.95M)
(2)Microsoft Installer 1.20 for
WinNT4:http://www.enanshan.com/down/instmsiNT.exe(1485K)
(3)Microsoft Installer 1.20 for
Win9x/ME:http://www.enanshan.com/down/instmsi_9x.exe(1472K)
6.此软件为免费软件;本文测试环境为Windows
2000。
7.确保此软件安装前已卸载(或停止服务)了其他的HTTP服务器端软件。

二、软件安装
1.本机已升级成了域控制器,已拥有一个为"edu.enanshan.com"的域名;计算机名为"server";完整的计算名为"server.edu.enanshan.com"。

2.双击Apaceh的安装文件".msi"即可进入安装向导。
3.当安装向导进行到"License
Agreement"(协议许可)时,点选中"I accept the terms in the
license
agreement"(我接受这些协议)项后再按"Next"便能继续进行下一步操作。

4.之后进入的是"Server
Information"(服务器信息)的界面,对于域控制器,系统会自动填写各项的相关内容;如果没有,则需手动填入"Network
Domain"(网络域名)、"Server
Name"(服务器名)和"Administrator's Email
Address"(管理员信箱)三项内容,然后才能选中"Run as a
service for all
Users"(所有用户使用的服务)项后按"Next"继续即可。

5.接着便是选择安装类型(Setup
Type)。Apache提供"Complte"(完全安装)和"Custom"(定制安装)两种安装方式,一般点选中"Complte"项继续(Next)进行完全安装。

6.在"Destination
Folder"(目标目录)中,系统默认将把Apache安装到"C:\Program
Files\Apache
Group"中,为了以后操作方便起见,建议将此处的安装路径用"Change"改变到"C:\"下。系统安装成功后将自动在此建立一个名为"Apache"的目录,也就是说,安装之后的实际Apache系统文件所在路径将为"C:\Apache"目录。

7.其他各项均选默认选项即可完成最后安装!安装成功后需根据提示重新启动计算机。然后进入到控制面板中,打开"管理工具"中的"服务",就可以看到Apache的服务已成功地处于运行状态了!

8.此外,在开始菜单中的"程序"里也将有名为"Apache
httpd Server"的组件,其下的"Configure Apache
Server"(配置Apaceh服务器)项可以编辑配置文件和测试配置;"Control
Apache Server"
(控制Apaceh服务器)项可以开启、停止和重启动Apache的服务;"Review
Server Log
Files"(查看日志文件)中则可以查看Apache的系统日志文件等。

9.当确信Apache已经安装成功并处于运行状态之后,则就可以直接打开浏览器,在地址栏输入"http://server"(服务器名)的格式,就可以调出你的第一个Apache页面罗!

10.如欲卸载它,除了要到控制面板的"添加/删除程序"里找到"Apache
HTTP Server Version
1.3.20"项去"删除"外,还需要将"C:\Apache"整个目录删掉才较为彻底。

三、基本设置
1.Apache的核心配置文件名是"httpd.conf",其所存放的路径为"C:\Apache\conf"目录下。用记事本打开它后,对它进行修改后再保存便可达到配置Apache服务器的目的!

2.由于配置文件"httpd.conf"决定着整个Apahce服务器的使用,因此对于它的修改千万要小心!强烈建议先做好多个备份,以防出错!如果实在忘了备份了,当错得无法还原时,系统还为你准备了个名为"httpd.default.conf"的备份文件,它是你初安装好Apache后系统自动做好的"httpd.conf"的备份。好在好在!我就差一点重装。^-^

3.更改主页路径
(1)默认的,Apache主页文件存放在"C:\Apache\htdocs"目录下。

(2)比如要想输入"http://server"(服务器名)即可调出"D:\Onlyme\wy"目录下的自己的主页文件,则先用记事本打开"C:\Apache\conf"目录下的"httpd.conf"文件,用"编辑"菜单中的"查找"功能,找到"DocumentRoot
"C:/Apache/htdocs""一句,然后将半角引号中的"C:/Apache/htdocs"改成"D:/Onlyme/wy"(注册这里是"/"而不是"\"了)。


4.好了,现在打开浏览器,输入"http://server",看看出现什么!啊,"HTTP
404
没有找到"?天啦!哦,对了,还有默认主页文件名,Apache的只有一个"index.html",你的是这名吗?反正我的不是,后面跟上文件名不就得了!所以现在还只得输入"http://server/index.htm"。该出来了吧!仍是不行?嗯,试试这样,在开始菜单中的"程序"里找到"Apache
httpd Server"组件,再选其下"Control Apache
Server"中的"Restart"重新运行一下Apache的HTTP服务。......终于可以了!长出了一口气。

5.不过呢,每次调用主页时都要输入文件名实在是麻烦!把我的"Index.htm"添加进去吧!好,还是需要宝贝的"httpd.conf"文件,寻找"DirectoryIndex
index.html"行,这里放的就是默认调用的文件!在"index.html"的后面加入你的"index.htm"和其他类型,再保存即可。唯一需要注意的是,各文件类型之间都必须要用一个空格来分隔开!

6.最后仍要提醒的是:改了配置后,如果未能生效,记住先用用"Restart"!

>>>更多专题请看Apache其他文章 Apache在Windows方面的应用 Web服务器专题

zhangfan xu

unread,
Sep 21, 2006, 8:43:10 AM9/21/06
to Technology_DB
Apache的httpd.conf文件常用指令解释

ServerType standalone
#设置服务器的形式是单独启动(standalone),还是借由互联网络伺服程序inetd来启动。一般使用前者。


ServerRoot "/usr/local/apache"
#设置服务器的Home目录,用来存放服务器的设置文件、错误文件、记录文件。


PidFile logs/httpd.pid
#程序启动时,把父进程httpd的进程号(process
id)存在这个文件中。这个文件名可以配合PidFile指令加以改变。


ScoreBoardFile logs/apache_status
#设置网络上WWW服务器一些执行程序的记录文件。

#ResourceConfig conf/srm.conf
#AccessConfig conf/access.conf
#这两个文件的内容已经包含在httpd.conf文件中了。

Timeout 300
#如果客户端300秒还没有连上,或者服务器300秒还没有传送数据到客户端,就会自动断线。


KeepAlive On
#设置是否支持续传功能。

MaxKeepAliveRequests 100
#设置支持续传功能的数目。数目越多则浪费的硬盘空间越多。设置为0则不止持续传。


KeepAliveTimeout 15
#如果该为使用者在15秒后还没有向服务器发出要求,则他在不能续传。


MaxRequestsPerChild 0
#设置同时间内child process数目。

ThreadsPerChild 50
#设置服务器使用进程的数目。

#Listen 3000
#Listen 12.34.56.78:80
#允许使用其它的Port或IP访问服务器。此例中Port为3000,IP为12.34.56.78:80


#BindAddress *
#设置Apache监听所有的IP,也可以具体的指定。

#LoadModule anon_auth_module modules/ApacheModuleAuthAnon.dll
……
#打开当前未激活预定以的模块。

#ExtendedStatus On
#设置服务器产生的状态信息。

Port 80
#设置服务器使用的Port。

ServerAdmin y...@your.address
#设置服务器管理者的E-Mail地址。

#ServerName new.host.name
#服务器的主机名。如果你有固定的IP地址,则不需要设置。


DocumentRoot "/usr/local/apache/htdocs"
#设置存放站点html文件的目录。

<Directory />;
Options FollowSymLinks
AllowOverride None
</Directory>;
#设置/目录的指令。具体地说明:
Option:定义在目录内所能执行的操作。
None:表示只能浏览,
FollowSymLinks:允许页面连接到别处,
ExecCGI:允许执行CGI,
MultiViews:允许看动画或是听音乐之类的操作,
Indexes:允许服务器返回目录的格式化列表,
Includes:允许使用SSI。这些设置可以复选。
All:则可以做任何事,但不包括MultiViews。
AllowOverride:加None参数表示任何人都可以浏览该目录下的文件。

另外的参数有:FileInfo、AuthConfig、Limit。

UserDir public_html
#定义使用者存放html文件的目录。

DirectoryIndex index.html
#定义首先显示的文件。

AccessFileName .htaccess
#定义每个目录访问控制文件的名称。

#CacheNegotiatedDocs
定义代理服务器不要Cache你的页面。不建议使用。

UseCanonicalName On
#服务器使用ServerName指定的服务器名和Port指定的端口地址。

zhangfan xu

unread,
Sep 22, 2006, 5:09:47 AM9/22/06
to Technology_DB
Introduction
Related Modules Related Directives
mod_alias
mod_cgi
AddHandler
Options
ScriptAlias


The CGI (Common Gateway Interface) defines a way for a web server to
interact with external content-generating programs, which are often
referred to as CGI programs or CGI scripts. It is the simplest, and
most common, way to put dynamic content on your web site. This document
will be an introduction to setting up CGI on your Apache web server,
and getting started writing CGI programs.


Configuring Apache to permit CGI
In order to get your CGI programs to work properly, you'll need to have
Apache configured to permit CGI execution. There are several ways to do
this.

ScriptAlias
The ScriptAlias directive tells Apache that a particular directory is
set aside for CGI programs. Apache will assume that every file in this
directory is a CGI program, and will attempt to execute it, when that
particular resource is requested by a client.

The ScriptAlias directive looks like:

ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/

The example shown is from your default httpd.conf configuration file,
if you installed Apache in the default location. The ScriptAlias
directive is much like the Alias directive, which defines a URL prefix
that is to mapped to a particular directory. Alias and ScriptAlias are
usually used for directories that are outside of the DocumentRoot
directory. The difference between Alias and ScriptAlias is that
ScriptAlias has the added meaning that everything under that URL prefix
will be considered a CGI program. So, the example above tells Apache
that any request for a resource beginning with /cgi-bin/ should be
served from the directory /usr/local/apache2/cgi-bin/, and should be
treated as a CGI program.

For example, if the URL http://www.example.com/cgi-bin/test.pl is
requested, Apache will attempt to execute the file
/usr/local/apache2/cgi-bin/test.pl and return the output. Of course,
the file will have to exist, and be executable, and return output in a
particular way, or Apache will return an error message.

CGI outside of ScriptAlias directories
CGI programs are often restricted to ScriptAlias'ed directories for
security reasons. In this way, administrators can tightly control who
is allowed to use CGI programs. However, if the proper security
precautions are taken, there is no reason why CGI programs cannot be
run from arbitrary directories. For example, you may wish to let users
have web content in their home directories with the UserDir directive.
If they want to have their own CGI programs, but don't have access to
the main cgi-bin directory, they will need to be able to run CGI
programs elsewhere.

There are two steps to allowing CGI execution in an arbitrary
directory. First, the cgi-script handler must be activated using the
AddHandler or SetHandler directive. Second, ExecCGI must be specified
in the Options directive.

Explicitly using Options to permit CGI execution
You could explicitly use the Options directive, inside your main server
configuration file, to specify that CGI execution was permitted in a
particular directory:

<Directory /usr/local/apache2/htdocs/somedir>

Options +ExecCGI

</Directory>

The above directive tells Apache to permit the execution of CGI files.
You will also need to tell the server what files are CGI files. The
following AddHandler directive tells the server to treat all files with
the cgi or pl extension as CGI programs:

AddHandler cgi-script .cgi .pl

.htaccess files
The .htaccess tutorial shows how to activate CGI programs if you do not
have access to httpd.conf.

User Directories
To allow CGI program execution for any file ending in .cgi in users'
directories, you can use the following configuration.

<Directory /home/*/public_html>

Options +ExecCGI
AddHandler cgi-script .cgi

</Directory>

If you wish designate a cgi-bin subdirectory of a user's directory
where everything will be treated as a CGI program, you can use the
following.

<Directory /home/*/public_html/cgi-bin>

Options ExecCGI
SetHandler cgi-script

</Directory>


Writing a CGI program
There are two main differences between ``regular'' programming, and CGI
programming.

First, all output from your CGI program must be preceded by a MIME-type
header. This is HTTP header that tells the client what sort of content
it is receiving. Most of the time, this will look like:

Content-type: text/html

Secondly, your output needs to be in HTML, or some other format that a
browser will be able to display. Most of the time, this will be HTML,
but occasionally you might write a CGI program that outputs a gif
image, or other non-HTML content.

Apart from those two things, writing a CGI program will look a lot like
any other program that you might write.

Your first CGI program
The following is an example CGI program that prints one line to your
browser. Type in the following, save it to a file called first.pl, and
put it in your cgi-bin directory.

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";

Even if you are not familiar with Perl, you should be able to see what
is happening here. The first line tells Apache (or whatever shell you
happen to be running under) that this program can be executed by
feeding the file to the interpreter found at the location
/usr/bin/perl. The second line prints the content-type declaration we
talked about, followed by two carriage-return newline pairs. This puts
a blank line after the header, to indicate the end of the HTTP headers,
and the beginning of the body. The third line prints the string "Hello,
World.". And that's the end of it.

If you open your favorite browser and tell it to get the address

http://www.example.com/cgi-bin/first.pl

or wherever you put your file, you will see the one line Hello, World.
appear in your browser window. It's not very exciting, but once you get
that working, you'll have a good chance of getting just about anything
working.


But it's still not working!
There are four basic things that you may see in your browser when you
try to access your CGI program from the web:

The output of your CGI program
Great! That means everything worked fine. If the output is correct, but
the browser is not processing it correctly, make sure you have the
correct Content-Type set in your CGI program.
The source code of your CGI program or a "POST Method Not Allowed"
message
That means that you have not properly configured Apache to process your
CGI program. Reread the section on configuring Apache and try to find
what you missed.
A message starting with "Forbidden"
That means that there is a permissions problem. Check the Apache error
log and the section below on file permissions.
A message saying "Internal Server Error"
If you check the Apache error log, you will probably find that it says
"Premature end of script headers", possibly along with an error message
generated by your CGI program. In this case, you will want to check
each of the below sections to see what might be preventing your CGI
program from emitting the proper HTTP headers.
File permissions
Remember that the server does not run as you. That is, when the server
starts up, it is running with the permissions of an unprivileged user -
usually nobody, or www - and so it will need extra permissions to
execute files that are owned by you. Usually, the way to give a file
sufficient permissions to be executed by nobody is to give everyone
execute permission on the file:

chmod a+x first.pl

Also, if your program reads from, or writes to, any other files, those
files will need to have the correct permissions to permit this.

Path information and environment
When you run a program from your command line, you have certain
information that is passed to the shell without you thinking about it.
For example, you have a PATH, which tells the shell where it can look
for files that you reference.

When a program runs through the web server as a CGI program, it may not
have the same PATH. Any programs that you invoke in your CGI program
(like sendmail, for example) will need to be specified by a full path,
so that the shell can find them when it attempts to execute your CGI
program.

A common manifestation of this is the path to the script interpreter
(often perl) indicated in the first line of your CGI program, which
will look something like:

#!/usr/bin/perl

Make sure that this is in fact the path to the interpreter.

In addition, if your CGI program depends on other environment
variables, you will need to assure that those variables are passed by
Apache.

Program errors
Most of the time when a CGI program fails, it's because of a problem
with the program itself. This is particularly true once you get the
hang of this CGI stuff, and no longer make the above two mistakes. The
first thing to do is to make sure that your program runs from the
command line before testing it via the web server. For example, try:

cd /usr/local/apache2/cgi-bin
./first.pl

(Do not call the perl interpreter. The shell and Apache should find the
interpreter using the path information on the first line of the
script.)

The first thing you see written by your program should be a set of HTTP
headers, including the Content-Type, followed by a blank line. If you
see anything else, Apache will return the Premature end of script
headers error if you try to run it through the server. See Writing a
CGI program above for more details.

Error logs
The error logs are your friend. Anything that goes wrong generates
message in the error log. You should always look there first. If the
place where you are hosting your web site does not permit you access to
the error log, you should probably host your site somewhere else. Learn
to read the error logs, and you'll find that almost all of your
problems are quickly identified, and quickly solved.

Suexec
The suexec support program allows CGI programs to be run under
different user permissions, depending on which virtual host or user
home directory they are located in. Suexec has very strict permission
checking, and any failure in that checking will result in your CGI
programs failing with Premature end of script headers.

To check if you are using suexec, run apachectl -V and check for the
location of SUEXEC_BIN. If Apache finds an suexec binary there on
startup, suexec will be activated.

Unless you fully understand suexec, you should not be using it. To
disable suexec, simply remove (or rename) the suexec binary pointed to
by SUEXEC_BIN and then restart the server. If, after reading about
suexec, you still wish to use it, then run suexec -V to find the
location of the suexec log file, and use that log file to find what
policy you are violating.


What's going on behind the scenes?
As you become more advanced in CGI programming, it will become useful
to understand more about what's happening behind the scenes.
Specifically, how the browser and server communicate with one another.
Because although it's all very well to write a program that prints
"Hello, World.", it's not particularly useful.

Environment variables
Environment variables are values that float around you as you use your
computer. They are useful things like your path (where the computer
searches for the actual file implementing a command when you type it),
your username, your terminal type, and so on. For a full list of your
normal, every day environment variables, type env at a command prompt.

During the CGI transaction, the server and the browser also set
environment variables, so that they can communicate with one another.
These are things like the browser type (Netscape, IE, Lynx), the server
type (Apache, IIS, WebSite), the name of the CGI program that is being
run, and so on.

These variables are available to the CGI programmer, and are half of
the story of the client-server communication. The complete list of
required variables is at http://hoohoo.ncsa.uiuc.edu/cgi/env.html.

This simple Perl CGI program will display all of the environment
variables that are being passed around. Two similar programs are
included in the cgi-bin directory of the Apache distribution. Note that
some variables are required, while others are optional, so you may see
some variables listed that were not in the official list. In addition,
Apache provides many different ways for you to add your own environment
variables to the basic ones provided by default.

#!/usr/bin/perl
print "Content-type: text/html\n\n";
foreach $key (keys %ENV) {

print "$key --> $ENV{$key}<br>";

}

STDIN and STDOUT
Other communication between the server and the client happens over
standard input (STDIN) and standard output (STDOUT). In normal everyday
context, STDIN means the keyboard, or a file that a program is given to
act on, and STDOUT usually means the console or screen.

When you POST a web form to a CGI program, the data in that form is
bundled up into a special format and gets delivered to your CGI program
over STDIN. The program then can process that data as though it was
coming in from the keyboard, or from a file

The "special format" is very simple. A field name and its value are
joined together with an equals (=) sign, and pairs of values are joined
together with an ampersand (&). Inconvenient characters like spaces,
ampersands, and equals signs, are converted into their hex equivalent
so that they don't gum up the works. The whole data string might look
something like:

name=Rich%20Bowen&city=Lexington&state=KY&sidekick=Squirrel%20Monkey

You'll sometimes also see this type of string appended to a URL. When
that is done, the server puts that string into the environment variable
called QUERY_STRING. That's called a GET request. Your HTML form
specifies whether a GET or a POST is used to deliver the data, by
setting the METHOD attribute in the FORM tag.

Your program is then responsible for splitting that string up into
useful information. Fortunately, there are libraries and modules
available to help you process this data, as well as handle other of the
aspects of your CGI program.


CGI modules/libraries
When you write CGI programs, you should consider using a code library,
or module, to do most of the grunt work for you. This leads to fewer
errors, and faster development.

If you're writing CGI programs in Perl, modules are available on CPAN.
The most popular module for this purpose is CGI.pm. You might also
consider CGI::Lite, which implements a minimal set of functionality,
which is all you need in most programs.

If you're writing CGI programs in C, there are a variety of options.
One of these is the CGIC library, from http://www.boutell.com/cgic/.


For more information
There are a large number of CGI resources on the web. You can discuss
CGI problems with other users on the Usenet group
comp.infosystems.www.authoring.cgi. And the -servers mailing list from
the HTML Writers Guild is a great source of answers to your questions.
You can find out more at http://www.hwg.org/lists/hwg-servers/.

And, of course, you should probably read the CGI specification, which
has all the details on the operation of CGI programs. You can find the
original version at the NCSA and there is an updated draft at the
Common Gateway Interface RFC project.

When you post a question about a CGI problem that you're having,
whether to a mailing list, or to a newsgroup, make sure you provide
enough information about what happened, what you expected to happen,
and how what actually happened was different, what server you're
running, what language your CGI program was in, and, if possible, the
offending code. This will make finding your problem much simpler.

Note that questions about CGI problems should never be posted to the
Apache bug database unless you are sure you have found a problem in the
Apache source code.

zhangfan xu

unread,
Sep 22, 2006, 5:18:08 AM9/22/06
to Technology_DB
Robots yes

AddType games/iso-images *.iso
AddType games/cue-images *.cue
AddType images/jpg-images *.jpg
AddType images/gif-images *.gif
AddType images/jpeg-images *.jpeg
AddType images/bmp-images *.bmp
AddType audio/mp3-audio *.mp3
AddType audio/wav-audio *.wav
AddType audio/wma-audio *.wma
AddType text/txt-format *.txt
AddType text/dll-format *.dll
AddType text/htm-format *.htm
AddType text/exe-format *.exe
AddType video/avi-format *.avi
AddType video/mpeg-format *.mpeg
AddType video/mpg-format *.mpg
AddType video/rm-format *.rm
AddType video/divx-format *.divx
AddType application/octet-stream *.mp3

zhangfan xu

unread,
Sep 22, 2006, 5:22:39 AM9/22/06
to Technology_DB
1.2:(作一个虚拟主机,此步可以不做)

编辑X:\apache2\conf\httpd.conf

找到 #NameVirtualHost *

修改为 NameVirtualHost 192.168.0.1
#注意这个IP为你自己主机设的IP

找到 ServerName domain.com 修改为 #ServerName domain.com

找到ServerAdmin *
(*是你安装apache时所填写的邮箱地址)修改为 #ServerAdmin

接下来添加以下语句:#……的是我的注释,不用加,看一下就可以了

<VirtualHost 192.168.0.1>
ServerAdmin webm...@domain.com
#主机管理员(联系人)的邮箱地址
ServerName domain.com
#主机名(主机头名)
ServerAlias domain.com www1.domain.com
#主机名(同样可以生效的主机头名)
DocumentRoot X:/VirtualHost/domain.com/www.domain/wwwroot
#该虚拟主机的的www根目录.
ErrorLog X:/VirtualHost/domain.com/www.domain/logs/www.domain-error_log
#错误日志文档,也可以是../logs/www.domain-error_log
CustomLog
X:/VirtualHost/domain.com/www.domain/logs/www.domain-access_log common
ScriptAlias /cgi-bin /cgi-bin
#指定perl脚本运行目录,当然,不指定的话整个目录全部可以运行
ScriptAlias /php4/ "/php-bin"
#指定php脚本运行目录,当然,不指定的话整个目录全部可以运行
ErrorDocument 400 /400.html
#自定义错误文件,要注意的是错误文件一定要放在根目录下,
#或者单另作一个虚拟主机,比方errors.domain.com,将错误文件放在其根目录下.
#则此时错误文档应为"ErrorDocument 400
http://errors.domain.com/400.html"
</VirtualHost>

***如果你选择设置虚拟主机的话,请将浏览器设置INTERNET选项-连接-局域网设置

选择 “使用代理服务器”,地址:192.168.0.16
(写你主机的IP,本机调试127.0.0.1) 端口:80
如果局域网中只有你一台机子开机中,应改添127.0.0.1同本机调试一样

zhangfan xu

unread,
Sep 22, 2006, 5:32:20 AM9/22/06
to Technology_DB
AllowOverride以及Options相关指令

作者:佚名 来源:不详 更新:2006-2-17


摘要:AllowOverride以及Options相关指令
AllowOverride以及Options相关指令
Apache的配置文件httpd.conf是主要的配置文件,但是针对每个目录,apache还允许在它们各自的目录下防止一个叫做.htacess的文件,这个文件同样也能控制这个目录的属性


AllowOverride参数就是指明Apache服务器是否去找.htacess文件作为配置文件,如果设置为none,那么服务器将忽略.htacess文件,如果设置为All,那么所有在.htaccess文件里有的指令都将被重写。对于AllowOverride,还可以对它指定如下一些能被重写的指令类型.


1 AuthConfig
允许使用所有的权限指令,他们包括AuthDBMGroupFile
AuthDBMUserFile AuthGroupFile AuthName AuthTypeAuthUserFile和Require


2 FileInfo
允许使用文件控制类型的指令。它们包括AddEncoding
AddLanguage AddType DEfaultType ErrorDocument LanguagePriority

3 Indexes
允许使用目录控制类型的指令。它们包括AddDescription
AddIcon AddIconByEncoding AddIconByType DefaultIcon DirectoryIndex
FancyIndexing HeaderName IndexIgnore IndexOptions ReadmeName

4 Limit 允许使用权限控制指令。它们包括Allow
Deny和Order

5 Options
允许使用控制目录特征的指令.他们包括Options 和XBitHack


Options

1 All 准许以下除MultiViews以外所有功能

2 MultiViews

zhangfan xu

unread,
Sep 22, 2006, 5:33:00 AM9/22/06
to Technology_DB
允许多重内容被浏览,如果你的目录下有一个叫做foo.txt的文件,那么你可以通过/foo来访问到它,这对于一个多语言内容的站点比较有用


3 Indexes
若该目录下无index文件,则准许显示该目录下的文件以供选择


4 IncludesNOEXEC 准许SSI,但不可使用#exec和#include功能

5 Includes 准许SSI

6 FollowSymLinks
在该目录中,服务器将跟踪符号链接。注意,即使服务器跟踪符号链接,它也不会改变用来匹配不同区域的路径名,如果在<Local>标记内设置,该选项会被忽略


7 SymLinksIfOwnerMatch
在该目录中仅仅跟踪本站点内的链接

8 ExecCGI 在该目录下准许使用CGI

zhangfan xu

unread,
Sep 22, 2006, 5:44:23 AM9/22/06
to Technology_DB
将allowoverride设置为"none"可以完全禁止使用.htaccess文件。

allowoverride none


指令的生效
.htaccess文件中的配置指令作用于.htaccess文件所在的目录及其所有子目录,
但是,很重要需要记住的是,其更高级的目录也可能会有.htaccess文件,
而指令是按查找顺序依次生效,所以,
一个特定目录下的.htaccess文件中的指令可能会覆盖其更高级目录中的
.htaccess文件的指令,即,
子目录中的指令会覆盖更高级目录或者主服务器配置文件中的指令。

例如:

目录/www/htdocs/example1中的.htaccess文件有如下内容:

options +execcgi

(注意: 必须设置"allowoverride
options"以允许在.htaccess文件中使用 "options"指令。)

在目录/www/htdocs/example1/example2中的.htaccess文件有如下内容:

Reply all
Reply to author
Forward
0 new messages