Apache在windows的设置
本节主要考虑windows的安装和配置使用,Linux 参考:http://httpd.apache.org/docs/2.2/stopping.html
一 Apache在windows的安装
主要支持windows NT 86系统,安装文件或源代码下载页:http://httpd.apache.org/download.cgi。
安装过程中下列参数需要指定:
1.
Network Domain. Enter the DNS domain in which your server is or will be registered in. For example, if your server's full DNS name is server.mydomain.net, you would type mydomain.net here.
2.
Server Name. Your server's full DNS name. From the example above, you would type server.mydomain.net here.
3.
Administrator's Email Address. Enter the server administrator's or webmaster's email address here. This address will be displayed along with error messages to the client by default.
4.
For whom to install Apache Select for All Users, on Port 80, as a Service - Recommended if you'd like your new Apache to listen at port 80 for incoming traffic. It will run as a service (that is, Apache will run even if no one is logged in on the server at the moment) Select only for the Current User, on Port 8080, when started Manually if you'd like to install Apache for your personal experimenting or if you already have another WWW server running on port 80.
5.
The installation type. Select Typical for everything except the source code and libraries for module development. With Custom you can specify what to install. A full install will require about 13 megabytes of free disk space. This does not include the size of your web site(s).
6.
Where to install. The default path is C:\Program Files\Apache Software Foundation under which a directory called Apache2.2 will be created by default.
二 Apache的配置
Apache安装过程的配置被记录到conf\httpd.conf中,在安装后可以修改或增加其他的配置,且Apache在windows上配置与unix有一定的不同,区别如下:
#
Because Apache for Windows is multithreaded, it does not use a separate process for each request, as Apache does on Unix. Instead there are usually only two Apache processes running: a parent process, and a child which handles the requests. Within the child process each request is handled by a separate thread.
The process management directives are also different:
MaxRequestsPerChild: Like the Unix directive, this controls how many requests a single child process will serve before exiting. However, unlike on Unix, a single process serves all the requests at once, not just one. If this is set, it is recommended that a very high number is used. The recommended default, MaxRequestsPerChild 0, causes the child process to never exit.
Warning: The server configuration file is reread when a new child process is started. If you have modified httpd.conf, the new child may not start or you may receive unexpected results.
ThreadsPerChild: This directive is new. It tells the server how many threads it should use. This is the maximum number of connections the server can handle at once, so be sure to set this number high enough for your site if you get a lot of hits. The recommended default is ThreadsPerChild 50.
#
The directives that accept filenames as arguments must use Windows filenames instead of Unix ones. However, because Apache uses Unix-style names internally, you must use forward slashes, not backslashes. Drive letters can be used; if omitted, the drive with the Apache executable will be assumed.
#
While filenames are generally case-insensitive on Windows, URLs are still treated internally as case-sensitive before they are mapped to the filesystem. For example, the <Location>, Alias, and ProxyPass directives all use case-sensitive arguments. For this reason, it is particularly important to use the <Directory> directive when attempting to limit access to content in the filesystem, since this directive applies to any content in a directory, regardless of how it is accessed. If you wish to assure that only lowercase is used in URLs, you can use something like:
RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lowercase:$1} [R,L]
#
Apache for Windows contains the ability to load modules at runtime, without recompiling the server. If Apache is compiled normally, it will install a number of optional modules in the \Apache2.2\modules directory. To activate these or other modules, the new LoadModule directive must be used. For example, to activate the status module, use the following (in addition to the status-activating directives in access.conf):
LoadModule status_module modules/mod_status.so
Information on creating loadable modules is also available.
#
Apache can also load ISAPI (Internet Server Application Programming Interface) extensions (i.e. internet server applications), such as those used by Microsoft IIS and other Windows servers. More information is available. Note that Apache cannot load ISAPI Filters.
#
When running CGI scripts, the method Apache uses to find the interpreter for the script is configurable using the ScriptInterpreterSource directive.
#
Since it is often difficult to manage files with names like .htaccess in Windows, you may find it useful to change the name of this per-directory configuration file using the AccessFilename directive.
#
Any errors during Apache startup are logged into the Windows event log when running on Windows NT. This mechanism acts as a backup for those situations where Apache cannot even access the normally used error.log file. You can view the Windows event log by using the Event Viewer application on Windows NT 4.0, and the Event Viewer MMC snap-in on newer versions of Windows.
三 运行Apache为service
默认的如果安装的时候选择所有人可用,则Apache被安装为service。该service可以在windows启动的时候自动启动。在Apache安装后Apache Monitor.exe也被安装,用来管理Apache服务。
You can install Apache as a Windows NT service as follows from the command prompt at the Apache bin subdirectory:
httpd.exe -k install
If you need to specify the name of the service you want to install, use the following command. You have to do this if you have several different service installations of Apache on your computer.
httpd.exe -k install -n "MyServiceName"
If you need to have specifically named configuration files for different services, you must use this:
httpd.exe -k install -n "MyServiceName" -f "c:\files\my.conf"
If you use the first command without any special parameters except -k install, the service will be called Apache2 and the configuration will be assumed to be conf\httpd.conf.
Removing an Apache service is easy. Just use:
httpd.exe -k uninstall
The specific Apache service to be uninstalled can be specified by using:
httpd.exe -k uninstall -n "MyServiceName"
Normal starting, restarting and shutting down of an Apache service is usually done via the Apache Service Monitor, by using commands like NET START Apache2 and NET STOP Apache2 or via normal Windows service management. Before starting Apache as a service by any means, you should test the service's configuration file by using:
httpd.exe -n "MyServiceName" -t
You can control an Apache service by its command line switches, too. To start an installed Apache service you'll use this:
httpd.exe -k start
To stop an Apache service via the command line switches, use this:
httpd.exe -k stop
or
httpd.exe -k shutdown
You can also restart a running service and force it to reread its configuration file by using:
httpd.exe -k restart
四 运行Apache为控制台程序
一般的建议运行Apache为service,但是也提供了运行Apache为控制台。
To run Apache from the command line as a console application, use the following command:
httpd.exe
Apache will execute, and will remain running until it is stopped by pressing Control-C.
You can tell a running Apache to stop by opening another console window and entering:
httpd.exe -k shutdown
This should be preferred over pressing Control-C because this lets Apache end any current operations and clean up gracefully.
You can also tell Apache to restart. This forces it to reread the configuration file. Any operations in progress are allowed to complete without interruption. To restart Apache, use:
httpd.exe -k restart
五 测试成功
在安装和配置后,应该可以使用http://localhost/ ,http://127.0.0.1/ 或http://127.0.0.1:8080/看到“it works”。
六 参考
1)http://httpd.apache.org/docs/2.2/platform/windows.html
2)http://httpd.apache.org/docs/2.2/
3)http://httpd.apache.org/docs/2.2/stopping.html
七 完!