Summary of Apache (HTTP) service knowledge (1)

Source: Internet
Author: User

Apache introduction:

Apache is a famous web server software. It is a tool for implementing the HTTP protocol, while httpd is the main program of the Apache Hypertext Transfer Protocol server.

Next I will talk about the Apache configuration file (very important)

1. The configuration file is divided into three parts:

Section1: Global Environment

Function: Controls global operations of Apache server processes.

Section2: 'main' Server Configuration

Function: Provides the configuration of the master server (the master server by default ).

Section3: Virtual Hosts

Function: provides virtual server configurations.

Note: by default, the master server is enabled, and the master server and the virtual server cannot be enabled at the same time. To enable the virtual server, first disable the master server.


2. Main content of Section 1 of section:

ServerTokens OS

Function: displays the apache version and operating system name.

Serverroot "/etc/httpd"

Function: Set the root directory of the server to/etc/httpd.

Pidfile run/httpd. PID (Note: This is the relative path. Add/etc/httpd before the absolute path)

Function: Specify the path where the process number file of the Apache server process is stored:/etc/httpd/run/httpd. PID.

Timeout 300

Function: Specify the connection timeout interval of 300 s.

Keeplive off

Function: sets whether persistent connections are allowed. If the value is off, persistent connections are not allowed. By default, only one file can be transmitted in one request.

# Maxkeepaliverequest 100

Function: sets a maximum of requests for a persistent connection. If the value is 0, no limit is allowed.

Keepalivetimeout 15

Function: the timeout value of a persistent connection is 15 s.

<Ifmodule prefork. c> (server pool)

<Ifmodule prefork. c>

Startservers 8 // when the server is enabled, eight sub-processes are started.

Minspareservers 5 // the minimum number of idle server sub-processes is 5

Maxspareservers 20 // The maximum number of idle server sub-processes is 20

Serverlimit 256 // The maximum number of server processes allowed is 256.

Maxclients 256 // a maximum of 256 clients are allowed at the same time.

Maxrequestsperchild 4000 // allows a maximum of 4000 Service requests from a server sub-process

</Ifmodule>


Listen 80 function: Set the listening port to port 80, and can be set as follows: IP: 80, indicating the port 80 of that IP


3. The main content of Section 2 of sectionis as follows:

User Apache

Group aapche

Function: Provides the identity for running Apache and the owner group: Apache basic group: Apache

Serveradmin [email protected]

Function: Set the email address of the Apache server administrator.

Servername {IP | Domain Name}: 80 // if this is a domain name, you need support from the DNS server.

Function: sets the default Apache site name and port number.

UseCanonicalName off

Function: sets whether to use a canonical name. When the value is off, the host name and port number provided by the client are used.

When the value is on, it indicates the value set with servername.

DocumentRoot "/var/www/html"

Function: sets the default document root directory for the web site. The page files on the website are stored in this root directory.

<Directory/>

Options followsymlinks

AllowOverride none

</Directory>

Function: Access Control of the root directory. <directory/> indicates that the directory of the file system needs to be restricted.


<Directory "/var/www/html">

Options indexes followsymlinks // you can follow the symbol to connect to the file. indexes indicates that if the document on the page to be accessed does not exist, the list of file directories under the root directory of the document is displayed.

AllowOverride NONE // the current configuration cannot be overwritten, that is, the. htaccess file is not processed.

Order allow, deny // Access Control Order, first allow and then deny

Allow from all // allow access from all hosts

</Directory>

Function: Access Control of the document root directory


<Ifmodule mod_userdir.c>

Userdir disabled

</Ifmodule>

Function: the personal homepage is disabled by default, while the userdir disable is open to the personal homepage.

Accessfilename. htaccess

Function: specify the name of the access control file in each directory as. htaccess

Hostnamelookups off

Function: Set whether the customer's name or IP address is recorded in the log. If it is off, the IP address is recorded. If it is on, the name is recorded.

Errorlog logs/error_log

Function: specify the location where error logs are stored.

Loglevel warn

Function: Specify the basic log record as a warning.

Customlog logs/access_log combined

Function: specify the location and type of access logs.

Log format

% H: client address

% L: Remote Login Name, usually-

% U: Enter the user name for authentication-

% T: the time when the server received the user request.

% R: the start line of the request for registration

%> S: response status code

% B: length of the response message, in bytes

% {Header_name} I: record the value corresponding to the specified Header


Serversignature on

Function: add a line to the page generated by the server. The displayed content is: Server version and virtual host name.

Alias/icons/"/var/www/icons /"

Function: Define/icons/as the alias of/var/www/icons,

ScriptAlias/cgi-bin/"/var/www/cgi-bin /"

Function: defines the script alias, that is, the alias/cgi-bin/is/var/www/cgi-bin /.

Indexoptions fancyindexing versionsort namewidth = * htmltable charset = UTF-8

Function: sets the display mode for automatically generated directory lists,

Fancyindexing // Add a small icon before each type of file to differentiate

Versionsort // sort multiple versions of the same software

Namewidth = * // The File Name field automatically adapts to the longest file name in the current directory


Adddefacharcharset UTF-8

Feature: Character Set setting, which is set to UTF-8 by default


<Location/Server-status>

# Sethandler server-status

# Order deny, allow

# Deny from all

# Allow from .example.com

# </Location>

Function: Set Apache to report detailed server status information.


Section3: mainly refers to the VM Host Configuration:

There are three types of virtual hosts: IP-based virtual hosts, Port-based virtual hosts, and name-based virtual hosts.

The VM cannot be enabled with the master server at the same time. comment out the VM.

Comment out the specified site root path of the master server: DocumentRoot


Define Virtual Host

Namevirtualhost IP: Port

<Virtualhost IP: Port>

Servername service name

DocumentRoot root directory

Serveralias service alias

Errorlog Error Log

Customlog access log

</Virtualhost>

In general, there are so many Apache configuration files. Of course there are still some that are not described, which is more important than writing them.


Port-based VM

First, comment out the DocumentRoot of the default server and specify another port, for example, port 8080.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/52/wKiom1PnQViCgtbaAAAPNClchso014.png "Title =" 1.png" alt = "wkiom1pnqvicgtbaaaapnclchso014.png"/>

Then you can edit the content of the VM: (the content is a bit simple and the log file is not written)

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/52/wKiom1PnQaiQW02oAAAlstD_33Y790.png "Title =" 2.png" alt = "wkiom1pnqaiqw02oaaalstd_33y790.png"/>

Then test the File Syntax httpd-T or service httpd configtest.

Then service httpd restart (modify the port number to restart the Service)

The test is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/53/wKioL1PnRVmTXF-rAAAgz5WJ9aQ345.png "Title =" 3.png" alt = "wKioL1PnRVmTXF-rAAAgz5WJ9aQ345.png"/>


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/53/wKiom1PnRGOiV4AlAAAiDoVpUKk620.png "Title =" 4.png" alt = "wkiom1pnrgoiv4alaaaidovpukk620.png"/>


Let's take a look at the implementation of IP-based virtual hosts: the configuration file is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/53/wKioL1PnRrWi2eoYAAAk9gboVw0063.png "Title =" 7.png" alt = "wkiol1pnrrwi2eoyaaak9gbovw0063.png"/>

We only need to change all ports to port 80, but the IP addresses cannot be the same.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/53/wKioL1PnRnCQkli-AAAlLGGO0vo996.png "Title =" 5.png" alt = "wKioL1PnRnCQkli-AAAlLGGO0vo996.png"/>


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/53/wKiom1PnRWGjJ0cvAAAlFwOWNtg980.png "Title =" 6.png" alt = "wkiom1pnrwgjj0cvaaalfwowntg980.png"/>

Finally, we often use host name-based implementation. to Resolve Host IP addresses based on host names, we must first be able to analyze host IP addresses. to Resolve Host Name IP addresses, We Need DNS services, therefore, configuring the DNS server is a prerequisite. Here, we only need to add the/etc/hosts file to the resolution database file of the configured DNS server,

Configuration file:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/53/wKioL1PnSu3CobA2AAAf53mJDUY487.png "Title =" 10.png" alt = "wkiol1pnsu3coba2aaaf53mjduy487.png"/>

Test syntax

Restart service

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/53/wKiom1PnSOmjr5UVAAAluCGy8HA532.png "Title =" 8.png" alt = "wkiom1pnsomjr5uvaaalucgy8ha532.png"/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/53/wKioL1PnSgzRTqvZAAAngoS7V94619.png "Title =" 9.png" alt = "wkiol1pnsgzrtqvzaaangos7v94619.png"/>


The above three types of virtual hosts are created. here, by the way, when I use a virtual machine based on the host name, I do not change the/etc/hosts of the virtual machine, I changed my windows local drive C/Windows/system32/Drivers/etc/hosts file. Add the following content to this file:

192.168.0.102 www1.stu14.com

192.168.0.102 www2, stu14.com


The above is a detailed description of the HTTP service configuration file and how to create a virtual host.


This article from the "Linux small pot friends" blog, please be sure to keep this source http://ny0716.blog.51cto.com/9154254/1538254

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.