Home > Operation and Maintenance > Apache > Introduction to the configuration file of the Apache server

Introduction to the configuration file of the Apache server

(*-*)浩
Release: 2019-11-28 11:34:02
Original
5768 people have browsed it

Introduction to the configuration file of the Apache server

Apache Main Configuration File

The main configuration file configures Apache by placing instructions in a plain text configuration file. The main configuration file is usually a text file named: httpd.conf. The location of this file is set at compile time, but can be overridden using the -f command line flag. (Recommended learning: Apache Server)

In addition, you can use the Include directive to add other configuration files, and you can use wildcards to include many configuration files. Any directive can be placed in any of these configuration files. Only Apache will recognize changes to the main configuration file when it is started or restarted.

The server also reads files containing mime document types; the filename is set by the TypesConfig directive and defaults to mime.types.

Configuration file syntax

The Apache configuration file contains one directive per line. The backslash \ can be used as the last character on a line to indicate that the instruction continues to the next line. There can be no other characters or spaces between the backslash and the end of the line.

The directives in the configuration file are not case-sensitive, but the parameters of the directive are usually case-sensitive. Lines starting with the pound sign # are treated as comments and ignored. Comments may not be included on the same line as configuration directives. Whitespace appearing before a directive is ignored, so you can indent the directive for clarity. Empty lines are also ignored.

You can use the syntax ${ENVVAR} to use the value of the shell environment variable in the configuration file line. If "ENVVAR" is the name of a valid environment variable, the value of that variable is substituted at that location in the configuration file line, and processing continues as if that text were found directly in the configuration file. (If the ENVVAR variable is not found, the characters ${ENVVAR} remain unchanged for subsequent stages in configuration file processing.)

After environment variable substitution, concatenate any consecutive lines and remove leading and trailing The maximum length of a line in a configuration file with spaces is 8192 characters.

You can use apachectl configtest or the -t command line option to check syntax errors in the configuration file without starting the server.

Modularity

Apache is a modular server. This means that only the most basic functionality is included in the core server. Extended functionality is available through modules that can be loaded into Apache. By default, the server is compiled with a basic set of modules.

If the server is compiled to use dynamically loaded modules, you can compile the modules separately and add modules at any time using the LoadModule directive. Otherwise, Apache must be recompiled to add or remove modules. Configuration directives can be conditional on the inclusion of a specific module by enclosing them in an block.

To view the modules currently compiled into the server, you can use the -l command line option.

Scope of directives Directives placed in the main configuration file apply to the entire server. If you only want to change part of the server's configuration, you can place directives in the , , , , , and sections.

These sections restrict the application of directives they contain to specific file system locations or URLs. They can also be nested, allowing very fine-grained configuration.

Apache can serve many different websites at the same time. This is called virtual hosting. Directives can also be scoped by placing them in the section so that they only apply to requests for a specific website.

Although most directives can be placed in any of these sections, some directives do not make sense in certain situations. For example, directives that control process creation can only be placed in the master server context. To find which directives can be placed in which sections, check the directive's context.

.htaccess file

Apache allows decentralized management of configuration through special files placed in the web tree. The special file is usually called .htaccess, but any name can be specified in the AccessFileName directive.

Directives placed in a .htaccess file apply to the directory where the file is placed and all subdirectories. .htaccess files follow the same syntax as the main configuration file. Since .htaccess files are read with every request, changes made to these .htaccess files take effect immediately.

To find directives that can be placed in a .htaccess file, check the context of the directive. Server administrators further control which directives can be placed in the .htaccess file by configuring the AllowOverride directive in the main configuration file.

The above is the detailed content of Introduction to the configuration file of the Apache server. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template