Apache httpd.conf Chinese Detailed _linux

Source: Internet
Author: User
Tags http request parent directory system log web services dns names port number
ServerRoot "/usr/local"
ServerRoot is used to specify the running directory of the daemon httpd, httpd will automatically change the current directory of the process to this directory after it is started, so if the file or directory specified in the settings file is a relative path, then the true path is located under this serverr oot-defined path.
Scoreboardfile/var/run/httpd.scoreboard
HTTPD uses Scoreboardfile to maintain the internal data of the process, so there is usually no need to change this parameter unless the administrator wants to run several Apache servers on a single computer, and each Apache server requires a separate setup file htt Pd.conf, and use a different scoreboardfile.
#ResourceConfig conf/srm.conf
#AccessConfig conf/access.conf
These two parameters, ResourceConfig and AccessConfig, are compatible with the old version of Apache that uses srm.conf and access.conf settings files. If there is no compatible need, the corresponding settings file can be specified as/dev/null, which means that no other settings file exists, and that only one file is used httpd.conf to save all of the setup options.
Pidfile/var/run/httpd.pid
Pidfile the specified file will record the process number of the httpd daemon, because httpd can automatically replicate itself, so there are multiple httpd processes in the system, but only one process is the first initiated process, it is the parent process for the other process, and sending a signal to the process affects all httpd processes. The process number of the httpd parent process is recorded in the file defined by the Pidfile.
Timeout 300
Timeout defines a time-out interval for client and server connections that will disconnect the client after this interval (in seconds).
KeepAlive on
In HTTP 1.0, a connection can only transmit one HTTP request at a time, and the keepalive parameter is used to support a single connection, multiple transfer features of the HTTP 1.1 version, so that multiple HTTP requests can be delivered in a single connection. Although only newer browsers support this feature, it is still open to use this option.
Maxkeepaliverequests 100
Maxkeepaliverequests the maximum number of requests for HTTP requests that can be made for a single connection. Setting its value to 0 will support an unlimited transmission request within a single connection. In fact, no client program requests too many pages in a single connection, and usually does not reach the upper limit to complete the connection.
KeepAliveTimeout 15
KeepAliveTimeout tests the time between multiple request transfers in a connection, and if the server has completed a request but has not received the next request from the client, the server disconnects after the interval exceeds the value set by this parameter.
Threadsperchild 50
Sets the number of server usage processes.
# This is based on the server response speed, the number is too large will slow
Maxrequestsperchild 30
A Web service that uses a subprocess to provide a service is a common way to connect a child process to a single connection, causing the problem that each connection requires a system operation to generate and exit the subprocess, making these additional processes occupy the computer's capacity for processing. So the best way to do this is to have a child process that can request services for multiple connections, this does not require these build, exit process system consumption, Apache in this way, once the connection is over, the child process does not quit, but stay in the system waiting for the next service request, which greatly improve performance.
However, due to the continuous application and release of memory in the process of neutron processing, more times will cause some memory garbage, which will affect the stability of the system and affect the efficient utilization of system resources. Thus, after a certain number of requests have been processed by a copy, a copy of the child process can be exited and a clean copy is replicated from the original HTT PD process, which can improve the stability of the system. In this way, the number of service requests processed by each subprocess is defined by the Maxre questperchild. The default setting value is 30, which is an overly conservative setting for FreeBSD systems with high stability characteristics and can be set to 1000 or higher, set to 0 to support unlimited service processing for each replica.
For security, set to zero
#Listen 3000
#Listen 12.34.56.78:80
#BindAddress *
The Listen parameter can specify that the server monitors HTTP requests for other ports in addition to the standard 80 ports. Because the FreeBSD system can have multiple IP addresses at the same time, you can also specify that the server listen only for HTTP requests to an IP address of a bindaddress</b>. If this is not configured, the server responds to requests for all IP.
Even if the bindaddress parameter is used, the server responds only to requests for one IP address, but by using the extended listen parameter, the HTTP daemon can still be allowed to respond to requests for other IP addresses. At this point the use of the Listen parameter is the same as the second example above. This more complex usage is primarily used to set up a virtual host. After that, you can define a virtual host for different IP with the VirtualHost parameter, but this usage is the method of setting up the virtual Host in the earlier HTTP 1.0 standard, each need an IP address for a virtual host, in fact it is not very useful. In HTTP 1.1, the support of the virtual host of single IP address multi domain is increased, which makes the setting of the virtual host more significant.
#ExtendedStatus on
Apache server can report its running state through special HTTP request, open this extendedstatus parameter can let server report more comprehensive running state information
---------------------------------------------------------------------------------
ServerAdmin you@your.address
What should change in the configuration file may only be serveradmin, which is used to configure the email address of the administrator of the WWW server, which will be returned to the browser under the condition of an error in the HTTP service so that Web users and administrators can contact and report errors. It is customary to use webmaster on the server as the administrator of the WWW server to send e-mail messages sent to webmaster to the real Web administrator through the alias mechanism of the mail server.
ServerName localhost
By default, this servername parameter is not required, and the server automatically obtains its name through the name resolution process, but if the server has a problem with the name resolution (usually incorrect for reverse parsing), or if there is no formal DNS name, you can also specify the I-P address here. The server does not start properly when the servername is set incorrectly.
Typically a Web server can have multiple names, and the client browser can use all these names or IP addresses to access the server, but in the absence of a virtual host defined, the server always responds to the browser with its own official name. ServerName defines the official name that the Web server admits itself, such as a server name (a type defined in DNS) Freebsd.exmaple.org.cn, also defines an alias (CNAME record) for the convenience of memory as www.exmaple.org.cn, then Apache automatically resolves the name freebsd.example.org.cn, so that no matter which name the client browser uses to send the request, the server always tells the client that the program is freebsd.example.org.cn. Although this is not generally a problem, consider that one day the server may migrate to another computer and only want to complete the migration task by changing the WWW alias configuration in DNS so that the client does not want to use FreeBSD to record the address of the server in its bookmarks. You must use ServerName to reassign the official name of the server.
DocumentRoot "/usr/local/www/data"
DocumentRoot defines the path to this server's external hypertext document, and the client request for your L is mapped to the Web page file in this directory. Subdirectories in this directory, as well as files and directories indicated using symbolic connections, can be accessed by the browser, only using the same relative directory name on the URL.
Note that symbolic connections, although logically located under the root document directory, can actually be located in any directory on the computer, so that clients can access directories outside of the root document directory, which increases flexibility while reducing security. Apache provides the FollowSymLinks option in Directory Access control to turn on or off features that support symbolic connections.
<directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
The Apache server can access control of documents for the directory, but access control can be implemented in two ways, one in the settings file Httpd.conf (or access.conf) is set for each directory, and the other is to set access control files in each directory, usually with the. htaccess name of the access control file. Although these two ways can be used to control browser access, however, the use of the configuration file method requires a reboot after each change httpd daemon, less flexible, so mainly used to configure the server system's overall security control strategy, It is more flexible and convenient to use the. htaccess file in each directory to set access control for a specific directory.
<directory "h:/web001" >
Directory statements are used to define access restrictions for a directory, where you can see the standard syntax for defining access restrictions for a directory. This setting for the previous example is for the root directory of the system, sets the option to allow symbolic connections, and uses allowoverride none to followsymlinks access control files under this directory to change the configuration here. This also means that you do not have to view the corresponding access control files in this directory.
Because Apache access control settings for a directory are able to be inherited by the next level of directory, the settings on the root directory affect its subordinate directory. Note that because of the allowoverride none setting, the Apache server does not need to view access control files under the root directory, nor does it need to view access control files at the following levels of directory until httpd.conf (or access.conf Allows you to view access control files for a directory by specifying the Allow alloworride. Because Apache is the inheritance of Directory access control, if access control files are allowed to be viewed from the root directory, then Apache must view access control files at one level, which can have an impact on system performance. By default, this feature of the root directory is turned off so that Apache searches down from the directory specified in httpd.conf, reducing the number of searches and increasing system performance. Therefore, the system root setting allowoverride None is not only helpful for system security, but also beneficial to system performance.
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
This defines the access settings for the directory where the system publishes the document and sets different allowoverride options to define the relationship between the directory settings in the configuration file and the security control file under the user directory, and the options option is used to define the attributes of the directory.
Access restrictions can be set by configuration files and access control files in each directory. The settings file is set by the administrator, and the access control files in each directory are set by the owner of the directory, so the administrator can specify whether the owner of the directory can overwrite the system's settings in the settings file, which requires AllowOverride parameter is set, you can usually set a value of:
Impact of allowoverride settings on the function of each directory access control file
All defaults to enable access control files to overwrite system configuration
None server ignores settings for access control files
Options allow access control files to define a directory using the option parameter
FileInfo allow access to the control file can be set using AddType parameters
Authconfig allows access to control files using the authentication mechanism for each user, such as Authname,authtype, which enables the directory owner to protect the directory with the password and user name
Limit allows limits on the IP address and name of the client accessing the directory
Each directory has a certain attribute, you can use the options to control some of the access features in this directory settings, the following are the common feature options:
Options set Server attribute settings
All of the directory attributes are valid, this is the default state
None of the directory attributes are valid
FollowSymLinks allows the use of symbolic connections, which makes it possible for browsers to access documents other than the document root (DocumentRoot)
SymLinksIfOwnerMatch allows access only if the purpose of a symbolic connection is owned by the same user as the symbolic connection itself, and this setting adds some security
EXECCGI allows CGI programs to be executed in this directory
Indexes allows browsers to generate an index of all the files in this directory, so that when there is no index.html (or other index file) in this directory, you can send a list of files in this directory to the browser.
In addition, an order, Allow, and deny parameters are used in the previous example, which is a way to control access based on the domain name and IP address of the browser in the limit statement. Where the order defines the sequence in which allow and deny are processed, while allow and deny access control settings for the first name or IP, the example uses allow from all to allow all clients access to the directory without any restrictions.
Userdir public_html (win32= "My documents/my Website")
When running the Apache server on a FreeBSD, all users on this computer can have their own page paths, shaped like Http://freebsd.example.org.cn/~user, You can map to the user's own page directory by using a wavy symbol plus a username. The mapping directory is a subdirectory under the user's home directory, whose name is defined with the Usedir parameter, and the default is public_html. If you do not want to provide Web services for the official user, use disabled as the Userdir parameter.
#
# allowoverride FileInfo authconfig Limit
# Options MultiViews Indexes symlinksifownermatch includesnoexec
#
# Order Allow,deny
# Allow from all
#
#
# Order Deny,allow
# Deny from all
#
#
Another use of directory is that you can define access control permissions for subdirectories that are distributed in different directories by using a simple pattern-matching approach. This setting requires that the Apache server perform additional processing on each path, thereby reducing the performance of the server, so the default does not open this access limit.
Here you can see another statement limit,limit statement is used for specific request methods to set access control, which can use the GET, post and other server-supported request methods to do limit parameters, to set the access restrictions on different request methods. It is generally possible to turn on the get, POST, and head three request methods, while shielding other request methods to increase security. Limit statements, you can use matching methods in order, Allow, Deny,allow, and Deny to restrict domain names and IP, except that the domain name is matched backwards from the back and the IP address is previously matched.
DirectoryIndex index.html
In many cases, the name of the document is not specified in the URL, but only a directory name is given. Then the Apache server will automatically return to the directory defined by DirectoryIndex files, of course, can specify multiple file names, the system will be in order to search the directory. When all files specified by DirectoryIndex do not exist, the Apache server can generate a list of all the files in this directory based on system settings, providing user selection. The Indexes option (Options Indexes) in the access control options for this directory must be turned on so that the server can generate a directory list, or Apache will deny access.
Accessfilename. htaccess
Accessfilename defines the file name of the access control file under each directory, and by default. htaccess, you can change the access control restrictions for different directories by changing this file.
Order Allow,deny
Deny from all
In addition to access control for the directory, you can set access control based on the file, which is the task of the file statement. With the file statement, you must accept the appropriate access control, regardless of the directory in which the files are located, as long as the names match. This statement is important for system security, such as the previous example will block all users from accessing the. htaccess file, so that the key security information in the htaccess is not captured by the customer.
Typesconfig/usr/local/etc/apache/mime.types
Typeconfig is used to set the name of a file that holds different MIME type data, and the default setting is/usr/local/etc/apache/mime.types under FreeBSD.
DefaultType Text/plain
If the Web server cannot determine the default type of a document, which usually means that the document uses a nonstandard suffix, the server sends the document to the client browser using the MIME type defined by DefaultType. The problem with setting this to Text/plain is that if the server cannot determine the MIME of the document, then most of the document is a binary document, but sent back using the Text/plain format, the browser will open it internally without prompting for saving. It is therefore recommended that you change this setting to Application/octet-stream so that the browser prompts the user to save it.
Mimemagicfile/usr/local/etc/apache/magic
In addition to judging the MIME type of the file from the suffix of the file, Apache can further analyze some of the features of the file to determine the true MIME type of the file. This feature is implemented by the Mod_mime_magic module, which requires a file that records various MIME type features for analysis and judgment. The above setting is a conditional statement, and if you load the module, you must specify the location of the corresponding flag file magic.
Hostnamelookups off
Usually, when connected, the server can only get the IP address of the client, and if you want to obtain the client's hostname for logging and providing to the CGI program, you need to use this hostnamelookups option to set it to on to turn on the DNS back-check feature. However, this causes the server to perform DNS queries on each client request, increasing the overhead and slowing the response, so the default setting is to turn off this option with off. When the option is turned off, the server does not get the host name of the client, and only the IP address is used to record the customer.
Errorlog/var/log/httpd-error.log
LogLevel warn
Logformat "%h%l%u%t \%r\"%>s%b \ "%{referer}i\" \ "%{user-agent}i\" "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
This defines the form of the system log and, for server error logging, defines different error log files and their contents by errorlog, loglevel.
For system access logs, the default use of the Customlog parameter to define the location of the log, by default, by using the combined parameter to specify that all access logs be placed in a single file, however, different kinds of access logs can be placed in a different log file, which is done through the The Customlog specifies a different record type to complete. Common represents a common request access record for a single page, Referer represents a reference record for each page, you can see the number of requests contained in a page, the agent represents the type record of the client, and it is clear that you can annotate the existing combined defined set line and use common, The Referer and the agent are used as Customlog parameters to specify logging files for different kinds of logs respectively.
Obviously, Logformat is the format used to define different types of logs for logging, where macro definitions beginning with% are used to record different content.
If the files specified by these parameters use a relative path, then the path is relative to the serverroot.
Serversignature on
In some cases, for example, when a customer requests a Web page that does not exist, the server generates an error document, and by default the Serversignature option is turned on, and the last line of the error document contains information such as the server's name, the Apache version, and so on. Some administrators prefer not to display this information, you can set this parameter to OFF, or set to email, the last line will be replaced by the serveradmin email prompt.
alias/icons/"/usr/local/www/icons/"
Options Indexes MultiViews
AllowOverride None
Order Allow,deny
Allow from all
The alias parameter is used to map the URL directly to the real location in the server file system, and the generic document will be queried in DocumentRoot, but the path defined using the alias will map directly to the corresponding directory and no longer be queried under DocumentRoot. Therefore, the alias can be used to map the paths of some common files, such as the icons path of the various common icons. This allows directories outside the document root (DocumentRoot) to be available to the browser, in addition to symbolic connections, by using the alias map.
Once you have defined a mapped path, you should use the directory statement to set access restrictions.
scriptalias/cgi-bin/"/usr/local/www/cgi-bin/"
AllowOverride None
Options None
Order Allow,deny
Allow from all
Scriptalias is also a mapping for URL paths, but unlike the alias, Scriptalias is the path used to map CGI programs, and the files under this path are defined as CGI programs that are executed to obtain results rather than directly returning their contents by the server. By default, the CGI program uses the Cgi-bin directory as the virtual path.
# Redirect Old-uri New-url
The redirect parameter is used to rewrite the URL, and when the browser accesses a resource that no longer exists on the server, the server returns to the browser with a new URL telling the browser to obtain resources from the URL. This is primarily used for documents that originally existed on the server, changed locations, and wanted to be accessible using old URLs to maintain compatibility with previous URLs.
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. 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. 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
When the URL of an HTTP request is a directory, the server returns the index file in this directory. However, if the default index file does not exist in a directory, and when the server is licensed to display a list of directory files, the list of files in this directory is displayed, and in order to make the list of files understandable, not just a simple list, you need the preceding settings parameters.
If you use the indexoptions fancyindexing option, you can refer to various icons for various types of documents in the list of directories generated by the server. and which type of file uses the icon, use the following addiconbyencoding, Addiconbytype, and AddIcon to define which icon to use, based on the MIME encoding, type, and suffix of the file. If you are unsure of the icon used by the document, use the default icon defined by DefaultIcon.
Similarly, you can use Adddescription to add different descriptions for different types of documents. Also, the server is under the directory, querying the files defined using Readmename and Headername (automatically plus. HTML suffixes, if they are not found, are searched using the. txt suffix, and if these files are found, the contents of those files are displayed first before the file list to make the list of ordinary catalogs more comprehensible.
Indexignore let the server ignore the file when listing the list of files, where the file name is defined using mode configuration.
AddEncoding x-compress Z
AddEncoding X-gzip GZ
AddEncoding is used to tell some MIME types that use compression, which allows the browser to extract operations.
AddLanguage en. en
AddLanguage Fr. fr
AddLanguage de. de
AddLanguage da. Da
AddLanguage el. El
AddLanguage it. it
Languagepriority en fr de
An HTML document can have versions of multiple languages at the same time, such as File1.html.en, file1.html.fr, and so on, for file1.html documents, and each language suffix must be defined using AddLanguage. This allows the server to send different language versions to clients in different countries by negotiating with the browser. Instead, languagepriority defines the priority of different languages to respond to requests for file1.html in the order in which they are not specifically required, using different language versions. There is not much practical application of this international capability.
Adddefaultcharset iso-8859-1
Standard code for browser selection
The Simplified Chinese website should read: GB2312
#AddType application/x-httpd-php3. phtml
#AddType Application/x-httpd-php3-source. Phps
The AddType parameter can specify a MIME type for a file of a particular suffix, where the setting overrides the setting in Mime.types.
#AddHandler Cgi-script. CGI
AddHandler is used to specify a non-static type of processing that defines a document as a non-static document type, needs processing, and returns processing results to the browser. For example, the setting in the above note is to set the file ending with. cgi to the Cgi-script type, and the server will start the CGI program for processing. If you need to execute a CGI program outside of the path defined in the previous aliasscript, you need to use this parameter to set it, and the file that ends with. CGI will be executed as a CGI program.
You must allow CGI programs to be executed in the. htaccess in the configuration file, in this directory, in the. htaccess, and in its parent directory, which needs to be set through the options execcgi parameter.
#AddType text/html. shtml
#AddHandler server-parsed. shtml
Another type of dynamic processing is server-parsed, in which the server itself analyzes the markup in the Web page and changes the markup to the correct HTML identity. Because server-parsed needs to process text/html type of documents, it first defines the corresponding. shtml as the text/html type.
However, to support SSI, you must first use the options includes in the configuration file (or. htaccess) to allow the documents under that directory to be SSI types, or use the options includesnoexec to allow the execution of common SSI flags. However, the external program referenced in it is not executed.
Another way to specify the server-parsed type is to use the Xbitback setting option, and if the Xbithack is set to ON, the server checks all text/html-type documents (including the document for the. html suffix), and if the file attribute is found to have an execution bit "x", The server considers it a server analysis document and needs to be processed by the server. It is recommended that you use AddHandler to set the Xbitback to off, because using Xbitback will perform additional checks on all HTML documents, reducing efficiency.
#AddHandler Send-as-is ASIS
#AddHandler imap-file Map
#AddHandler type-map var
The annotated addhandler above is used to support the ASIS, map, and VAR processing capabilities of the Apache server.
# Action Media/type/cgi-script/location
# Action Handler-name/cgi-script/location
Because of the limited processing capabilities available within Apache, you can use the action to define an external program for the server as a dynamic document type that can be processed, and these external programs, like standard CGI programs, are the result of outputting different MIME types after data processing of the input. For example, to define an operation that performs wri2txt for a special suffix WRI and then returns the result, you can use:
Action Windows-writer/bin/wri2txt
AddHandler Windows-writer WRI
Further, you can use the action definition to perform a pre-processing operation on a MIME type, which requires the action parameter setting for the first format in the example. This setting does not require additional AddHandler to associate the processing operation with the file suffix, but instead uses the action to process MIME-type files directly. However, if the document suffix does not have a formal MIME type, you need to first define a MIME type.
#ErrorDocument "The server made a boo boo.
#ErrorDocument 404/missing.html
#ErrorDocument 404/cgi-bin/missing_handler.pl
#ErrorDocument 402 http://some.other_server.com/subscription_info.html
If a customer requests a Web page that does not exist, or does not have access rights, the server generates an error code and responds to a Web page that identifies the error in the client's browser. ErrorDocument is used to set the content that should respond to the client browser when an error occurs, errordocument the first parameter is the wrong sequence number, the second parameter is the response data, can be simple text, local Web page, local CGI program, and Web page on the remote host.
Browsermatch "MOZILLA/2" nokeepalive
Browsermatch "MSIE 4\.0b2;" Nokeepalive downgrade-1.0 force-response-1.0
Browsermatch "RealPlayer 4\.0" force-response-1.0
Browsermatch "java/1\.0" force-response-1.0
Browsermatch "jdk/1\.0" force-response-1.0
The Browsermatch command sets special parameters for specific client programs to ensure compatibility with older browsers and to support new browser features.
#
#ProxyRequests on
#
#
# Order Deny,allow
# Deny from all
# Allow from. your_domain.com
#
#ProxyVia on
#CacheRoot "/usr/local/www/proxy"
#CacheSize 5
#CacheGcInterval 4
#CacheMaxExpire 24
#CacheLastModifiedFactor 0.1
#CacheDefaultExpire 1
#NoCache a_domain.com another_domain.edu joes.garage_sale.com
#
The Apache server itself has the function of an agent, yet this requires loading into the Mod_proxy module. This can be judged using the Ifmodule statement and, if there is a mod_proxy module, use proxyrequests to open proxy support. The following directory is used to set access rights settings for the proxy function, and to set the individual parameter settings for buffering.
-------------------------------------------------------------------------------------
#NameVirtualHost 12.34.56.78:80
#NameVirtualHost 12.34.56.78
#
# ServerAdmin Webmaster@host.some_domain.com
# documentroot/www/docs/host.some_domain.com
# ServerName Host.some_domain.com
# ErrorLog Logs/host.some_domain.com-error_log
# Customlog Logs/host.some_domain.com-access_log Common
#
#
#
These contents in the default settings file are used when the virtual host server is used to set the naming foundation. where namevirtualhost to specify the IP address used by the virtual host, this IP address will correspond to multiple DNS names, and if Apache uses the listen parameter to control multiple ports, then you can add a port number here to further differentiate between different connection requests for different ports. Thereafter, using the VirtualHost statement, use the IP address specified by Namevirtualhost as a parameter to define the corresponding virtual host settings for each name.
The virtual host is on a Web server that can provide Web services for multiple individual domain names, and each domain name is completely independent, including a completely independent document directory structure and settings, so that the domain name is completely independent, not only using each domain name access to the content completely independent, And another domain name is not available to access the content of the Web page provided by other domain names.
The concept of a virtual host is very useful for ISPs, because although an organization can hang its own web pages on servers with other domain names, it is more formal and acceptable to use separate domain names and root URLs. Traditionally, you have to set up a server to achieve the purpose of a single domain name, however, this requires maintaining a separate server, many small units lack sufficient maintenance capacity, more appropriate way is to hire someone else to maintain the server. ISP also does not need to provide a separate server for an organization, fully can use the virtual host capabilities, so that the server for a number of domain names to provide Web services, and different services do not interfere with each other, external performance as a number of different servers.
There are two ways to set the virtual host, one is based on the HTTP 1.0 standard, the need for a server with multiple IP addresses, and then configure the DNS server, to each IP address with a different domain name, the last to configure Apache configuration files, so that the server to different domain names return different Web documents. Because this requires the use of an additional IP address, the domain name for each service to use a separate IP address, so this way to achieve more problems.
You can bind more than one IP address to a network interface, and you will need to use the alias parameter of Ifconfig to perform this configuration, but this can affect network performance FreeBSD.
The HTTP 1.1 standard allows the server to track which host name the browser requests when communicating with browsers and servers in the protocol. So you can use this new feature to set up a virtual host in a more relaxed way. This approach does not require additional IP addresses, but requires a new version of browser support. This approach has become the standard way to build a virtual host.
To establish a non-IP based virtual host, multiple domain names are an essential configuration, because each domain name corresponds to a virtual host to serve. Therefore, you need to change the configuration of the DNS server to add multiple CNAME options for the server, such as:
FreeBSD in A 192.168.1.64
Vhost1 in CNAME FreeBSD
Vhost2 in CNAME FreeBSD
The basic setup options are for the FreeBSD host set, and if you want to set up a virtual host for Vhost1 and Vhost2, use the VirtualHost statement to define different options, and in the statement you can use most of the options in front of the configuration file. You can redefine almost all the settings for the server.
Namevirtualhost 192.168.1.64
Documentroot/usr/local/www/data
ServerName freebsd.example.org.cn
Documentroot/vhost1
ServerName vhost1.example.org.cn
Documentroot/vhost2
ServerName vhost2.example.org.cn
It should be noted here that VirtualHost's parameter address must be consistent with the address defined by Namevirtualhost, and that all values are strictly consistent, and the Apache server admits that these definitions are virtual hosts defined for this IP address.
In addition, once the namevirtualhost is defined, access to the IP address is differentiated by different virtual hosts, while access to other IP addresses, such as 127.0.0.1, applies the previously defined default options.
----------------------------------------------------------------------------------------
Namevirtualhost www.xxx.org
(For dynamic IP alternative methods: Specify the IP of the virtual host, because to map the domain name to IP, can not use localhost,127.0.0.1, computer name, such as the address, so, you can again through the domain name conversion, the domain name to IP, so you do not have to change the IP every time.) )
#
# VirtualHost Example:
# Almost any Apache directive could into a virtualhost container.
# the ' The ' the ' the ' the ' I VirtualHost ' used for requests without a known
# server name.
#
<virtualhost 192.168.0.1> (Virtual host IP)
ServerAdmin 111@xxx.com (First virtual host email)
DocumentRoot h:/web001 (First virtual host directory)
ServerName www.xxx.org (First virtual host domain name)
ErrorLog Logs/www.xxx.org-error.log (First virtual host error log)
Customlog Logs/www.xxx.org-access.log Common (first virtual host data)
</VirtualHost>
<virtualhost 192.168.0.2> (Virtual host IP)
ServerAdmin 111@xxx.com (second virtual host email)
DocumentRoot h:/web002 (Second virtual host directory)
ServerName www.xxx2.org (second virtual host domain name)
ErrorLog Logs/www.xxx2.org-error.log (second virtual host error log)
Customlog Logs/www.xxx2.org-access.log Common (second virtual host data)
</VirtualHost>
By analogy, you can add more virtual hosts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.