The configuration commands of the Apache server are not divided into three concentrated parts.
1. Configure the environment variables of the Apache server throughout the running process.
2. Configure the detailed interface parameters for the master server or default server.
3. Set the virtual server so that Web requests with different IP addresses or different host names can be completed on the same Apache server.
(That is, a physical server can be set to a virtual server with multiple IP addresses or multiple host names)
Part 1: Environment Settings
# Set the server startup mode: standalone or inetd.
Start.
# The default value is standalone ).
Servertype Standalone
# Set the Server Directory to store the server's configuration files, error files, and record files.
# Note: The slash "/" cannot be added at the end of the directory "/".
Serverroot "C:/Apache"
# When the service program starts, it saves the process ID of the parent program httpd to this
# Log/httpd. PID file. The file name can be changed with the pidfile command.
Pidfile logs/httpd. PID
# Set the record file of the Apache server execution program.
Scoreboardfile logs/apache_status
# The following two items are my preferences. If you think the httpd. conf file is too long, you cannot find what you need.
# You can put the required settings in SRM. conf (which has only a few lines) and open it below:
# The following two settings are enabled in the standard configuration. we can disable them.
# Remove "#" before the next line and enable SRM. conf
# Resourceconfig CONF/SRM. conf
# Accessconfig CONF/access. conf
# Maximum waiting time between the server and client
# If the client has not been connected in 300 seconds, or the server has not transferred data to the client in 300 seconds, it will be automatically disconnected
Line. Timeout 300
# Set whether to support continuous data transfer. Supported by default
Keepalive on
# Set the number of support for continuous data transfer. The larger the quantity, the larger the hard disk space wasted, and the better the performance.
# If it is set to 0, there is no limit.
Maxkeepaliverequests 100
# Set the maximum waiting time for continuous transfer
# If a connected user does not send a request to the server 15 seconds later, the user cannot use the Resume function.
Keepalivetimeout 15
# Set the number of sub-processes in the same time. For security purposes, set it to zero.
Maxrequestsperchild 0
# Set the number of processes used by the server.
# This is based on the server's response speed. If the number is too large, it will slow down.
Threadsperchild 50
# Allow another port or IP address to access the server. You can open it.
# Listen 3000.
# Listen 12.34.56.78: 80
# Set the IP address of the Apache listener, which is also the IP address of the virtual server on your local machine.
Bindaddress 127.0.0.1
# Open a pre-activated module. Do not change it unless you need it.
# Loadmodule anon_auth_module modules/apachemoduleauthanon. dll
.
# Set the status information generated by the server. If it is set to "on", detailed information is generated.
# Extendedstatus on
--------------------------------------------------------------------------------
Part 2 Detailed interface parameter settings
# Set the port used by the server for independent use.
Port 80
# Set the email address of the Server Manager.
Serveradmin siron@phpstar.com
# Server host name. If you have a fixed IP address, you do not need to set
Servername localhost
# Set the directory for storing site HTML files
DocumentRoot "C:/Apache/htdocs"
# Set/directory commands. The details are as follows:
# Option: defines the operations that can be performed in the directory.
# None indicates that only browsing is allowed.
# Followsymlinks allows the page to be connected elsewhere,
# Execcgi allows CGI execution,
# Multiviews allows operations such as watching animations or listening to music,
# Indexes allows the server to return a formatted list of directories,
# Supported des allows ssi.
# You can check these settings. All can do anything, but does not include Multiviews.
# AllowOverride:
# Adding the "NONE" parameter indicates that anyone can browse the files in this directory but will not read the files.
# Fileinfo allows the use of commands that control file types,
# Authconfig allows the use of authentication commands,
# Indexes allows the use of Directory Index commands,
# Limit allows the use of commands for controlling access to hosts,
# Options allows you to control the use of commands specific to directories.
# If it is set to all, the server will allow all commands.
<Directory/>
Options followsymlinks
AllowOverride none
</Directory>
# Define the first file to be displayed.
# You can change directoryindex index.html index.htm in this way
Directoryindex index.html
# Define the name of each directory access control file
Accessfilename. htaccess
# Define the proxy server not to cache your page. It is not used by default.
# Cachenegotiateddocs
# This command sets the location of the MIME type configuration file,
# The file name is relative to serverroot. We do not recommend that you change this file.
Typesconfig CONF/mime. Types
# The server will record the error message to a record,
# The file name can be set using the errorlog command.
# Different error records can be set for different virtual hosts
Errorlog logs/error. Log
# Set the record format
Logformat "% H % L % u % t/" % R/"%> S % B" common
.
.
.
# Alias commands allow files to be stored in a local file system other than DocumentRoot
# The ScriptAlias command is the same as the alias command, but it also indicates that the directory contains the CGI or PHP command file.
# The addtype command uses the specified content type as the sub-file name of the file ending with the file name
Alias/icons/"C:/Apache/icons /"
Alias/test/"C:/PHP/test /"
Alias/admin/"C:/admin/PHPmyAdmin /"
ScriptAlias/PHP/"C:/PHP /"
Addtype application/X-httpd-PHP. php
Addtype application/x-httpd-php3. php3
Action application/X-httpd-PHP "/PHP/php.exe"
# Addicon, addiconbyencoding and addiconbytype
# Is used to set the graph list used to display different file types. For each column
# The output file type. The first matching graph is displayed.
Addiconbytype (VID,/icons/movie.gif) Video /*
Addicon/icons/binary.gif. bin. exe
# Default file illustration
Defaulticon/icons/unknown.gif
# If a problem or error occurs, you can configure Apache for four responses.
#1. Output custom (mizmized) messages (text)
# Errordocument 500 "the server made a boo.
#2. re-import a local URL to solve this problem/Error
# Errordocument 404/missing.html
# Errordocument 404/cgi-bin/missing_handler.pl
#3. re-import to an external URL to handle this issue/Error
# Errordocument 402 http://some.other _ server.com/subscription_info.html
3. Set virtual web
IP-type VM
An IP host is the unique IP address of each VM. Multi-IP, so
Laris2.5 and Windows NT both support this method.
You can configure multiple VM instances in either of the following ways:
1. Start an httpd process for each VM.
Use this method in the following cases:
1) Security Isolation needs to be considered, for example, two httpd run on different users, groups, listen, serverroot, and two
Users cannot access other data except browsing data through the Web.
2) provides sufficient memory and file descriptors.
Setting method:
Create an independent httpd installation for each virtual host. In the configuration file httpd. conf of each installation path, use
The listen command specifies the IP address of the process service, for example, listen 10.68.37.10: 80.
2. Start an httpd process for all virtual hosts.
Use this method in the following cases:
1) allows sharing httpd configurations between virtual hosts.
2) computers serve a large number of requests and run multiple processes to reduce server performance.
Setting method:
In the configuration file httpd. conf, use the virtualhost command to set serveradmin and serverna for each virtual host.
Me, DocumentRoot, errorlog, transferlog, or customlog, for example:
<Virtualhost www.smallco.com> # IP address is recommended here
Serveradmin webmaster@mail.smallco.com
DocumentRoot/usr/local/etc/httpd/htdocs/smallco
Servername www.smallco.com # we recommend that you use a domain name here
Errorlog/usr/local/etc/httpd/logs/smallco/error_log
Transferlog/usr/local/etc/httpd/logs/smallco/access_log
</Virtualhost> 〉
<Virtualhost www.baygroup.org> # IP address is recommended here
Serveradmin webmaster@mail.baygroup.org
DocumentRoot/groups/baygroup/WWW
Servername www.baygroup.org # domain names are recommended here
Errorlog/groups/baygroup/logs/error_log
Transferlog/groups/baygroup/logs/access_log
</Virtualhost> 〉
At the same time, you need to configure the virtual network port or network card, and configure the corresponding settings in DNS.
Name-based VM (supported by apache1.3 or later versions)
Although the IP type VM is good, it is not the best solution. It requires that each VM has a dedicated IP address on some machines.
Difficult to implement. A name-based VM has different names, but the IP address is the same. Its advantage is that it is unlimited.
The number of virtual hosts, which is easy to configure and use without additional hardware and software. The disadvantage is that the client must support this part of the Protocol,
Browsers of the latest version are supported, but some earlier versions are not supported. However, Apache provides a solution for this.
Setting method:
In the configuration file httpd. conf, use the namevirtualhost command to set the virtual host, for example:
Namevirtualhost 111.22.33.44
<Virtualhost 111.22.33.44> # IP address is recommended.
Servername www. domain. TLD # domain name is recommended here
DocumentRoot/web/Domain
</Virtualhost> 〉
At the same time, the DNS defines www. domain. TLD pointing to 111.22.33.44.
Note: When the IP address is used after the namevirtualhost command, any URL request using the IP address is for the VM,
The master server will never respond to a URL request using an IP address. In addition, some servers want to be accessed by multiple names. Example
For example, if a server with an IP address wants to be accessed by domain. TLD and www2.domain. TLD
The virtualhost command uses the serveralias command. For example, serveralias domain. TLD *. domain. TLD
Additional VM configuration instances are provided.
Appendix: VM instance settings
IP-type VM Configuration
Setup 1: the server has two IP addresses,
111.22.33.44 server. domain. TLD
111.22.33.55 www. otherdomain. TLD
Www. domain. TLD is the alias of server. domain. TLD (cname), representing the master server.
Server Configuration:
...
Port 80
DocumentRoot/www/Domain
Servername www. domain. TLD
<Virtualhost 111.22.33.55> 〉
DocumentRoot/www/otherdomain
Servername www. otherdomain. TLD
...
</Virtualhost> 〉
Setup 2: basically the same as setup1, but no dedicated master server is set.
Server Configuration:
...
Port 80
Servername server. domain. TLD
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/Domain
Servername www. domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.55> 〉
DocumentRoot/www/otherdomain
Servername www. otherdomain. TLD
...
</Virtualhost> 〉
This setting hits the master server only when the URL is http://server.domain.tld
Setup 3: the server has two IP addresses,
111.22.33.44 server. domain. TLD
111.22.33.55 www-cache.domain.tld
Www. domain. TLD is the alias of server. domain. TLD (cname), representing the master server.
The www-cache.domain.tld is the proxy-cache, the port is 8080, and the Web server uses the default 80.
Server Configuration:
...
Port 80
Listen 111.22.33.44: 80
Listen 111.22.33.55: 8080
Servername server. domain. TLD
<Virtualhost 111.22.33.44: 80> 〉
DocumentRoot/www/Domain
Servername www. domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.55: 8080> 〉
Servername www-cache.domain.tld
...
<Directory Proxy:> :〉
Order deny, allow
Deny from all
Allow from 111.22.33
</Directory> 〉
</Virtualhost> 〉
Name-based VM Configuration
Setup 1: the server has an IP address,
111.22.33.44 server. domain. TLD.
Www. domain. TLD and www. sub. domain. TLD are aliases (cnames ).
Server Configuration:
...
Port 80
Servername server. domain. TLD
Namevirtualhost 111.22.33.44
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/Domain
Servername www. domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/subdomain
Servername www. sub. domain. TLD
...
</Virtualhost> 〉
If you use an IP address to access the server, because www. domain. TLD has the highest priority, it is considered as the default server or
Server 1.
Setup 2: the server has two IP addresses,
111.22.33.44 server1.domain. TLD for master server
111.22.33.55 server2.domain. TLD for VM
The alias www. domain. TLD is used for the master server,
The alias www. otherdomain. TLD is used for a VM,
The alias www. sub. domain. TLD, *. sub. domain. TLD is used for another VM,
Server Configuration:
...
Port 80
Servername www. domain. TLD
DocumentRoot/www/Domain
Namevirtualhost 111.22.33.55
<Virtualhost 111.22.33.55> 〉
DocumentRoot/www/otherdomain
Servername www. otherdomain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.55> 〉
DocumentRoot/www/subdomain
Servername www. sub. domain. TLD
Serveralias *. sub. domain. TLD
...
</Virtualhost> 〉
Hybrid (IP/Name) VM Configuration
Setup: the server has three IP addresses,
111.22.33.44 server. domain. TLD is used for name-Type Virtual Hosts
111.22.33.55 www. otherdomain1.tld for IP-Type Virtual Hosts
111.22.33.66 www. otherdomain2.tld for IP-Type Virtual Hosts
Server Configuration:
...
Port 80
Servername server. domain. TLD
Namevirtualhost 111.22.33.44
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/Domain
Servername www. domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/subdomain1
Servername www. sub1.domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.44> 〉
DocumentRoot/www/subdomain2
Servername www. sub2.domain. TLD
...
</Virtualhost> 〉
<Virtualhost 111.22.33.55> 〉
DocumentRoot/www/otherdomain1
Servername www. otherdomain1.tld
...
</Virtualhost> 〉
<Virtualhost 111.22.33.66> 〉
DocumentRoot/www/otherdomain2
Servername www. otherdomain2.tld
...
</Virtualhost> 〉
Port-type VM Configuration
Setup: the server has an IP address,
111.22.33.44 www. domain. TLD
If you do not need another alias or IP address, you can use a port-type virtual host to set a virtual server with different configurations.
VM instance.
Server Configuration:
...
Listen 80
Listen 8080.
Servername www. domain. TLD
DocumentRoot/www/Domain
<Virtualhost 111.22.33.44: 8080> 〉
DocumentRoot/www/domain2
...
</Virtualhost> 〉