Apache服务器配置全攻略(6)
通常连接时, 服务器 仅仅可以得到客户机的IP地址,如果要想获得客户机的 主机名,以进行日志记录和提供给 CGI程序使用,就需要使用这个HostnameLookups 选项,将其设置为On打开DNS反查功能。但是这将使 服务器 对每次客户请求都进行DNS查询,增加了系统开销
通常连接时,服务器仅仅可以得到客户机的IP地址,如果要想获得客户机的主机名,以进行日志记录和提供给 CGI程序使用,就需要使用这个HostnameLookups 选项,将其设置为On打开DNS反查功能。但是这将使服务器对每次客户请求都进行DNS查询,增加了系统开销,使得反应变慢,因此缺省设置为使用Off关闭此选项。关闭选项之后,服务器就不会获得客户机的主机名,而只能使用IP地址来记录客户。
ErrorLog /var/log/httpd-error.log
LogLevel warn
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent} "" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
#CustomLog /var/log/httpd-access.log common
#CustomLog /var/log/httpd-referer.log referer
#CustomLog /var/log/httpd-agent.log agent
CustomLog /var/log/httpd-access.log combined
这里定义了系统日志的形式,对于服务器错误记录, 由ErrorLog、 LogLevel 来定义不同的错误日志文件及其记录内容。
对于系统的访问日志,缺省使用CustomLog参数定义日志的位置,缺省使用 combined 参数指定将所有的访问日志放在一个文件中,然而也可以将不同种类的访问日志放在不同的日志记录文件中,这是通过在 CustomLog中指定不同的记录类型来完成的。common表示普通的对单页面请求访问记录,referer表示每个页面的引用记录,可以看出一个页面中包含的请求数,agent表示对客户机的类型记录,显然可以将现有的 combined 定义的设置行注释掉,并使用common、referer和agent作为CustomLog的参数,来为不同种类的日志分别指定日志记录文件。
显然,LogFormat是用于定义不同类型的日志进行记录时使用的格式, 这里
使用了以%开头的宏定义,以记录不同的内容。
如果这些参数指定的文件使用的是相对路径,那么就是相对于ServerRoot的
路径。
ServerSignature On
一些情况下,例如当客户请求的网页并不存在时,服务器将产生错误文档,
缺省情况下由于打开了 ServerSignature选项,错误文档的最后一行将包含服务器的名字、Apache的版本等信息。有的管理员更倾向于不对外显示这些信息,就
可以将这个参数设置为Off,或者设置为Email,最后一行将替换为对 ServerAdmin 的Email提示。
Alias /icons/ "/www/icons/"
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
Alias参数用于将URL与服务器文件系统中的真实位置进行直接映射,一般的
文档将在DocumentRoot 中进行查询,然而使用Alias定义的路径将直接映射到相
应目录下,而不再到DocumentRoot 下面进行查询。因此Alias可以用来映射一些
公用文件的路径,例如保存了各种常用图标的icons路径。这样使得除了使用符号连接之外,文档根目录(DocumentRoot)外的目录也可以通过使用了Alias映射,提供给浏览器访问。
定义好映射的路径之后,应该需要使用Directory语句设置访问限制。
ScriptAlias /cgi-bin/ "/www/cgi-bin/"
AllowOverride None
Options None
Order allow,deny
Allow from all
ScriptAlias也是用于URL路径的映射,但与Alias的不同在于,ScriptAlias 是用于映射CGI程序的路径,这个路径下的文件都被定义为CGI程序,通过执行它们来获得结果,而非由服务器直接返回其内容。缺省情况下CGI程序使用cgi-bin目录作为虚拟路径。
# Redirect old-URI new-URL
Redirect参数是用来重写URL的,当浏览器访问服务器上的一个已经不存在的资源的时候,服务器返回给浏览器新的URL,告诉浏览器从该URL中获取资源。这主要用于原来存在于服务器上的文档,改变了位置之后,而又希望能使用老URL能访问到,以保持与以前的URL兼容。
IndexOptions FancyIndexing
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
DefaultIcon /icons/unknown.gif
#AddDescription "GZIP compressed document" .gz
#AddDescription "tar archive" .tar
#AddDescription "GZIP compressed tar archive" .tgz
ReadmeName README
HeaderName HEADER
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
当一个HTTP请求的URL为一个目录的时候,服务器返回这个目录中的索引文件。但如果一个目录中不存在缺省的索引文件,并且该服务器又许可显示目录文件列表的时候,就会显示出这个目录中的文件列表,为了使得这个文件列表能具有可理解性,而不仅仅是一个简单的列表,就需要前面的这些设置参数。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://<server IP or domain name>/server-status), or view the Apache configuration file (ServerVersion: Apache/<version number>).

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

How to view the Apache version? Start the Apache server: Use sudo service apache2 start to start the server. View version number: Use one of the following methods to view version: Command line: Run the apache2 -v command. Server Status Page: Access the default port of the Apache server (usually 80) in a web browser, and the version information is displayed at the bottom of the page.

How to configure Zend in Apache? The steps to configure Zend Framework in an Apache Web Server are as follows: Install Zend Framework and extract it into the Web Server directory. Create a .htaccess file. Create the Zend application directory and add the index.php file. Configure the Zend application (application.ini). Restart the Apache Web server.

Apache cannot start because the following reasons may be: Configuration file syntax error. Conflict with other application ports. Permissions issue. Out of memory. Process deadlock. Daemon failure. SELinux permissions issues. Firewall problem. Software conflict.

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.
