Apache/"target =" _ blank "> Apache configuration is configured in the httpd. conf file. Therefore, the following configuration commands are modified in the httpd. conf file.
Configuration of the primary site (basic configuration)
(1) Basic Configuration:
ServerRoot "/mnt/software/apache2" # location of your apache software installation. If no absolute path is specified for other specified directories, the directory is relative to this directory.
PidFile logs/httpd. pid # the location of the Process number file of the first httpd process (parent process of all other processes.
Listen 80 # Port Number of the server listener.
ServerName www.jb51.net: 80 # main site name (website host name ).
ServerAdmin admin@jb51.net # administrator email address.
DocumentRoot "/mnt/web/clusting" # webpage storage location of the primary site.
Access Control for the Directory of the main site is as follows:
<Directory "/mnt/web/clusting">
Options FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all
</Directory>
The preceding Directory attribute configuration mainly includes the following options:
Options: What features are used for configuration in a specific directory? common values and basic meanings are as follows:
ExecCGI: Execute CGI scripts in this directory.
FollowSymLinks: in this directory, the file system is allowed to use symbols to connect.
Indexes: if the user cannot find the main page file specified by directoryindex(for example, index.html), the list of files in the directory is returned to the user.
SymLinksIfOwnerMatch: a symbolic connection is accessible only when the owner of the symbolic connection is the same as the owner of the actual file.
Www.2cto.com
AllowOverride: indicates the type of the command that is allowed to exist in the. htaccess file. The file name of the. htaccess file can be changed. The file name is determined by the AccessFileName command ):
None: When AllowOverride is set to None. Do not search for. htaccess files in this directory (you can reduce the server overhead ).
All: All commands can be used in the. htaccess file.
For other available values and meanings (for example, Options FileInfo AuthConfig Limit), see: http://www.jb51.net/Apache/ApacheManual/mod/core.html#AllowOverride
Order: control which of the Allow and Deny access rules takes precedence during access:
Allow: List of hosts that can be accessed (available domain names or subnets, for example, Allow from 192.168.0.0/16 ).
Deny: List of Access Denied hosts.
For more detailed usage, see: http://www.jb51.net/Apache/ApacheManual/mod/mod_access.html#order
DirectoryIndex index.html index.htm index. php # settings of the home page file (in this example, the home page file is set to index.html, index.htm and index. php)
(2) server optimization (MPM: Multi-Processing Modules)
The main advantage of apache2 is that it provides better support for multi-processor, and uses the-with-mpm option to determine the working mode of apache2 during compilation. If you know the working mechanism used by apache2, you can use the httpd-l command to list all modules of apache:
Prefork: If httpd-l lists prefork. c, you need to configure the following segments:
<IfModule prefork. c>
StartServers 5 # Number of httpd processes started when apache is started.
MinSpareServers 5 # minimum number of idle processes maintained by the server.
MaxSpareServers 10 # maximum number of idle processes maintained by the server.
MaxClients 150 # maximum number of concurrent connections.
MaxRequestsPerChild 1000 # the number of times each sub-process is killed after it is requested for service. 0 indicates no restriction. We recommend that you set it to 1000.
</IfModule>
In this mode, five httpd processes are started after the server is started (six parent processes are added, which can be seen through the ps-ax | grep httpd command ). When a user connects, apache uses an idle process to serve the connection, and the parent process fork a sub-process. Until the idle process in the memory reaches MaxSpareServers. This mode is used to be compatible with earlier versions of programs. My default options during compilation.
Worker: If httpd-l lists worker. c, you need to configure the following sections:
<IfModule worker. c>
StartServers 2 # Number of httpd processes started when apache is started.
MaxClients 150 # maximum number of concurrent connections.
MinSpareThreads 25 # minimum number of Idle threads maintained by the server.
MaxSpareThreads 75 # maximum number of Idle threads maintained by the server.
ThreadsPerChild 25 # Number of threads produced by each sub-process.
MaxRequestsPerChild 0 # the number of times each sub-process is killed after it is requested for service. 0 indicates no restriction. We recommend that you set it to 1000.
</IfModule>
This mode is used by threads to listen to customer connections. When a new client connects, one of the Idle threads accepts the connection. The server starts two processes at startup. The number of threads produced by each process is fixed (determined by ThreadsPerChild). Therefore, there are 50 threads at startup. When 50 threads are insufficient, the server automatically forks a process and generates 25 more threads.
Perchild: If httpd-l lists perchild. c, you need to configure the following segments:
<IfModule perchild. c>
NumServers 5 # Number of sub-processes started at server startup
StartThreads 5 # Number of threads started when each sub-process starts
MinSpareThreads 5 # minimum number of Idle threads in the memory
MaxSpareThreads 10 # maximum number of Idle threads
MaxThreadsPerChild 2000 # maximum number of requests to each thread before exiting. 0 is not restricted.
MaxRequestsPerChild 10000 # the number of times each sub-process is fork again. 0 indicates no restriction.
</IfModule>
In this mode, the number of sub-processes is fixed and the number of threads is not limited. When the client is connected to the server, Idle threads provide services. If the number of Idle threads is insufficient, the child process automatically generates threads to serve the new connection. This mode is used for multi-site servers.
(3) HTTP return header configuration:
ServerTokens Prod # This parameter sets the apache version information returned by the http header. The available values and meanings are as follows:
Prod: only the software name, for example, apache
Major: includes the main version number, for example, apache/2.
Minor: contains the Minor version number, for example, apache/2.0.
Min: only the complete apache version, for example, apache/2.0.54
OS: includes the operating system type, for example, apache/2.0.54 (Unix)
Full: Includes modules and module versions supported by apache, such as Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7g
ServerSignature Off # whether the server version information is displayed when an error occurs on the page. Recommended to Off
(4) persistent connection settings
KeepAlive On # enable the persistent connection function. That is, when the client connects to the server, the connection status remains unchanged after the data is downloaded.
MaxKeepAliveRequests 100 # maximum number of requests for a connection service.
KeepAliveTimeout 30 # How long does the connection last? If no data is requested for the connection, the connection is closed. The default value is 15 seconds.
Alias settings
For pages that are not in the directory specified by DocumentRoot, you can use a symbolic connection or an alias. The alias settings are as follows:
Alias/download/"/var/www/download/" # You can enter: http://www.jb51.net/download/ when accessing
<Directory "/var/www/download"> # Set access control for this Directory
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow, deny
Allow from all
</Directory>
CGI settings
ScriptAlias/cgi-bin/"/mnt/software/apache2/cgi-bin/" # access can be: http://www.jb51.net/cgi-bin. However, the CGI script file in this directory must have the executable permission!
<Directory "/usr/local/apache2/cgi-bin"> # Set Directory Properties
AllowOverride None
Options None
Order allow, deny
Allow from all
</Directory>
Personal Homepage settings (public_html)
UserDir public_html (the user's home page is stored in the public_html directory under the user's home directory URL http://www.jb51.net /~ Bearzhang/file.html will read the/home/bearzhang/public_html/file.html file)
Chmod 755/home/bearzhang # enables other users to read the file.
UserDir/var/html (the URL http://www.jb51.net /~ Bearzhang/file.html will read/var/html/bearzhang/file.html)
UserDir/var/www/*/docs (the URL http://www.jb51.net /~ Bearzhang/file.html will read/var/www/bearzhang/docs/file.html)
Log Settings
(1) Setting of error logs
ErrorLog logs/error_log # log storage location
LogLevel warn # Log Level
Displayed in the following format:
[Mon Oct 10 15:54:29 2005] [error] [client 192.168.10.22] access to/download/failed, reason: user admin not allowed access
(2) access log settings
The default log formats are as follows:
LogFormat "% h % l % u % t" % r "%> s % B" % {Referer} I "" % {User-Agent} I "combined
LogFormat "% h % l % u % t" % r "%> s % B" common # common is the log format name
LogFormat "% {Referer} I-> % U" referer
LogFormat "% {User-agent} I" agent
CustomLog logs/access_log common
Parameters in the format are as follows:
% H-Client IP address or host name
% L-The RFC 1413 identity determined by The client identd. The output symbol "-" indicates that The information here is invalid.
% U-name of the customer accessing the webpage obtained by the HTTP Authentication System. Valid only when authentication is available. The "-" symbol in the output indicates that the information here is invalid.
% T-time when the server completes processing the request.
"% R"-the quotation marks indicate the request content sent by the customer that contains many useful information.
%> S-the status code returned by the server to the client.
% B-the last response is the number of bytes that are returned to the client, excluding the response header.
"% {Referer} I"-This item indicates the webpage from which the request was submitted.
"% {User-Agent} I"-This item is the browser identification information provided by the customer's browser.
The following is an example of an access log:
192.168.10.22-bearzhang [10/Oct/2005: 16: 53: 06 + 0800] "GET/download/HTTP/1.1" 200 1228
192.168.10.22--[10/Oct/2005: 16: 53: 06 + 0800] "GET/icons/blank.gif HTTP/1.1" 304-
192.168.10.22--[10/Oct/2005: 16: 53: 06 + 0800] "GET/icons/back.gif HTTP/1.1" 304-