Configuring Apache's Httpd.conf (host part)

Source: Internet
Author: User
Tags response code fully qualified domain name

Httpd.conf The primary server partial configuration:

1. ServerName Instructions

The servername directive is an important instruction for defining the Apache default hostname, but this directive is commented out by default in httpd.conf, so to enable it, you need to first delete the # before servername, then add your site name or IP address. It is recommended to use the full IP address, for example:

Servername www.jonsk.com or Servername 172.16.3.9

If you do not use this command to specify the default host name, you will receive the following error message when Apache starts:

$./apachectl atarthttpd:could not reliably determine the server ' s fully qualified domain name,using 127.0.0.1 for Serve Rname

You will be prompted not to find the domain name, so you can only use 127.0.0.1 address as the default address of the server, and this address is only a network loopback address, only native access. If you use the full site name, Apache chooses to find the IP that corresponds to the site name from the local hostname list (/etc/hosts) or the IP that corresponds to DNS for the site name, based on the configuration of the host's host.conf file.

2. ServerRoot Instructions

The serverroot directive is used to define the directory where the server is located, which is usually specified by the "-prefix=serverroot Path" option during compilation, and it will contain folders such as Bin,conf,htdocs, as the root directory of Apache. But if you are using a binary package to install, then this serverroot is usually located in the/etc/apache2 directory, for example: Serverroot/etc/apache2.

3. DocumentRoot Instructions

The documentroot directive is used to specify the root directory of the page service provided by Apache, which contains the root (/) directory of URL requests received by Apache. For example: documentroot/srv/www/httpd/, this path needs to be represented by an absolute path, rather than using a relative path. If there are spaces in the path, you also need to enclose it in quotation marks.

4. ServerAdmin Instructions

The serveradmin directive is used to define the administrator email address that is prompted to the client when an error occurs on the server. such as: ServerAdmin [email protected]

5. Serveralias and alias instructions

These two instructions function Similarly, are used to implement the mapping directory function, but Serveralias is to identify the mapped directory as a CGI script directory, and all the files in this directory as a CGI script, and alias is only mapped to a normal directory, and is not recognized as a CGI script.

6. User and group instructions

The user and group directives define the accounts and workgroups that run the Apache server, which define the accounts and workgroups of the child processes created when the user requests, and work within the defined accounts and the power of the workgroup. Such as:

After Apache starts, you can use PS XAU |grep httpd to see if Apache uses Deamon to start a child process. The permissions for a httpd process in the list are root, which is the master process of Apache, which does not respond to any requests, it is only responsible for responding to user requests by establishing a child process. Apache can be launched in different distributions using different user and group accounts, daemon in Debian, www or Apache in other systems, or Www-data if compiled on its own.

7. Listen Instructions

The listen directive is used to define the Apache listener port number, default is 80, the port number range is 0~65535, the theory is can use all the port number in this range, but this 0~1204 is reserved for the system service, so it is not recommended to use, If you use a port other than 80, the client needs to add the upper-port number when accessing the service, for example: listen:8088.

8. LoadModule Instructions

The LoadModule instruction is used to load modules or target files, for example: LoadModule cgi_module modules/mod_cgi.so

When an Apache error occurs, an HTTP response code is given, and the information page corresponding to the error code is displayed according to the response code, in order to make the error page more friendly and easier to read. We can use the ErrorDocument directive to customize the error message page provided by the server error based on the response code, there are three ways to use it: Define text information, use a script, specify a page. For example: ErrorDocument "Unknown Error", which defines a text message for the 500 response code, replacing the 500 response code information with this text message. ErrorDocument 404 "/srv/www/cgi-bin/missing_404.pl", defines a script for the 400 response code, executes the script when this error occurs, and sends the result to the user. ErrorDocument 402 http://www.jonsk.com/info_402.html, define a link page for the 402 response code and send the page to the user if a 402 error occurs.

9. Options directive

The options directive determines which servers are used in which directories, and these features are as follows:

    • None: The options Directive will have no effect if this parameter is used.

    • EXECCGI: Allows CGI scripts to be executed in the current directory.

    • Includes: Allows the use of SSI functionality, which is the ability to turn on server-side inclusion (SSI).

    • IncludesNOEXEC: Allows the use of SSI functionality, but "#exec cmd" and "#exec CGI" functions are prohibited.

    • Indexes: When indexing is enabled, for example, a request to directory URL does not have an index file specified by the DIRECTORYINDEX directive, then the server automatically returns a list of directories that request directory content.
    • FollowSymLinks: Allows symbolic connections to be used in the current directory, but is ignored if the parameter is in the <Location> container, and does not change the path used to match the <Directory> container.

Configuring the Apache Httpd.conf (host part)

Related Article

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.