Configuration and use of Apache Web Server

Source: Internet
Author: User

The previous article describes how to install and start the Apache Web server. This article describes how to configure it to achieve special functions.

Apache configuration commands are divided into two types: one is used by core modules such as core and HTTP, which must be included in the httpd. conf file, and the other is used by standard or third-party modules.

1. Basic configuration instructions

The configuration in httpd. conf can be divided into three parts: master server, container configuration, and extension.

Master server: used to configure core service parameters as global commands, such as defining host names and listening ports.

Container configuration section: configuration section in the <container Name>... </container Name> style, such as virtual host, directory, and file permissions

Extended Part: External configuration files loaded in the include Mode

1.1 master server configuration

Servername defines the host name. If no host name exists, replace it with an IP address.

Serverroot defines the root directory where the httpd server process is installed. The value of layout varies.

DocumentRoot defines the root directory that provides the page documentation. This directory is the root directory that receives the URL request and must use an absolute path. If the path contains spaces, quotation marks are required.

Serveradmin specifies the email address of the website administrator

Alias/ScriptAlias define alias

User/Group specifies the user name and group for running the server process

Listen specifies the server listening port

Loadmodule/LoadFile: load the module or target file

Errordocument code content specifies the processing page or content of the error code. The page can be a script or string.

Options is used to specify the processing features in the directory, which has the following values, which can be combined through +-

Execcgi allows the current directory to execute CGI scripts

Supported des allows the SSI Function

Indexes account index function, that is, if the index file is not specified by the direcotryindex command, the list of files in the request directory is returned.

Followsymlinks allows the directory to use Symbolic Links

All features except Multiviews

Multiviews enables the multi-view feature provided by the mod_negotiations Module

1.2 container configuration

It is worth noting that container configurations can be nested as needed.

<Ifmodule! Module name> determine whether the module is loaded, and decide whether to execute the container configuration based on the true or false. The module name can be added! Indicates not loaded

<Ifdefine def> judge whether def is defined, and decide whether to execute the container configuration based on the true or false. Add def before! Undefined

The configuration in the <directory dir> area takes effect only for Dir, which is used to limit the configuration range or overwrite the global configuration. The directory can be a full path or a wildcard matching directory. Note that *? [] Cannot cross/

If you need regular expression matching, add ~

<Directorymatch> same as above, but it does not need to be added when it accepts regular expressions ~

<File> only for file Definition

<Filematch> same as above

<Location> access control for network URLs

<Locationmatch> same as above, regular matching is acceptable

Note that container rules have a priority in applications. Apache processes the priority from high to low as follows: direcotry. htacess direcotrymatch file filematch location high-priority rules will invalidate low-priority rules. At the same time, directory containers are sorted in alphabetical order by directory name. Mixing or improper use of these Rules may cause security issues. Therefore, it is not recommended to use complex rules. Restrict symbolic links when using files and directories.

1.3 extensions

There is an extra directory in the default configuration folder of Apache, which defines common configurations of other modules and can be loaded through the include command.

Common configuration functions are as follows:

Httpd-autoindex.conf automatic index Configuration

Configuration of httpd-info.conf mod_status info module

Httpd-mpm.conf MPM Configuration

Httpd-ssl.conf SSL Configuration

Httpd-userdir.conf user directory configuration, used to provide web sites for multiple users on a server, map users to their own directory

Httpd-vhosts.conf Virtual Host Configuration

1.3.1 mod-Dir

This module allows you to specify the index file. The configuration is as follows:

Directoryindex index.html index. php

In this way, when the user accesses the root directory, if there is a corresponding file below, the server will redirect the user to the index file page.

1.3.2 mod-Autoindex

1.3.3 mod-userdir

1.4 Configuration Tool

The localization tool Webmin needs to be installed locally and opened on the webpage. You can set it in Gui mode.

In Windows, zecos apacheconf can read remote httpd. conf via SSH to display the configuration.

2. Virtual Host Configuration

A vm allows us to open multiple websites on a single machine to direct access to different website pages through different domain names or IP addresses.

2.1 name a VM

After the domain name-based VM function is enabled, the server can direct to different sites based on the host header in the request. You must configure DNS cooperation before applying the domain name-based VM.

The configuration is relatively simple. The following example is a simple example.

## Use name-based virtual hosting.#NameVirtualHost *:80## VirtualHost example:# Almost any Apache directive may go into a VirtualHost container.# The first VirtualHost section is used for requests without a known# server name.#<VirtualHost *:80>    ServerAdmin    DocumentRoot /www/docs/    ServerName    ServerAlias    ErrorLog logs/    CustomLog logs/ common</VirtualHost>

A website is created here, which listens to all requests of 80 on the local host. However, this VM only provides the website service about because it uses an alias, it can also be accessed using an alias, however, the premise is that DNS records are configured. Note that IPv6 addresses should be enclosed in brackets.

Naming-based virtual hosts do not support http1.0 and earlier protocols, and do not support SSL protocol (the SSL protocol requires an independent host name to match the IP address ). To support SSL, you need to listen to port 443 and establish site services on this port. For more information, see the example of the httpd_ssl.conf file.

2.2 IP Virtual Host

IP virtual hosts require that our server host be configured with multiple IP addresses. We configure different websites to different IP addresses, which can be multiple virtual interface addresses of the same physical Nic.

The configuration method is as follows:

<VirtualHost>    ServerAdmin postmaster@dummy-host2.localhost    DocumentRoot "D:/xampp/htdocs/dummy-host2.localhost"    ServerName dummy-host2.localhost    ServerAlias www.dummy-host2.localhost    ErrorLog "logs/dummy-host2.localhost-error.log"    CustomLog "logs/dummy-host2.localhost-access.log" combined</VirtualHost>

2.3 dynamic VM Method

For other methods, such as creating a large number of virtual hosts through the vhost_alias_module or rewrite_module, this function is generally used by website providers. For details, refer to Apache documentation.

3. Performance Configuration

4. Log Control

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: 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.