Ubuntu Network Application Server Apache configuration Basics

Source: Internet
Author: User
Tags mime file
Ubuntu Network Application Server Apache configuration basics-Linux Enterprise Application-Linux server application information, the following is a detailed description. Configuration File

The main configuration file of Apache officially released is httpd. conf. The server will also read a file containing the MIME file type, and its file name is determined by the TypesConfig command. The default value is mime. types.

The main configuration file of Apache in Ubuntu/Debian is/etc/apache2/apache2.conf, and the file containing the MIME file type is/etc/mime. types.

In addition, to split the configuration by logic, you can use the Include command and wildcard to append many other configuration files. The following configuration file is attached to Ubuntu:

# Configurations that contain dynamic modules:
Include/etc/apache2/mod-enabled/*. load
Include/etc/apache2/mod-enabled/*. conf

# Include your own configurations:
Include/etc/apache2/httpd. conf

# Configurations that contain port listening:
Include/etc/apache2/ports. conf

# Contains a general configuration statement segment:
Include/etc/apache2/conf. d/[^. #] *

......

# Configuration commands containing virtual hosts:
Include/etc/apache2/sites-enabled/[^. #] *

Configuration File Syntax

*
Each line contains an instruction, and the backslash (\) can be used at the end of the line to indicate continued rows.
*
Commands in the configuration file are case-insensitive, but the command parameters (argument) are usually case-sensitive.
*
Rows starting with "#" are considered as annotations and ignored during reading. The annotation cannot appear behind the instruction.
*
Blank lines and blank characters before commands are ignored during reading. Therefore, indentation can be used to keep the configuration level clear.

Both the main configuration file and the configuration file contained in the Include statement should comply with the Apache configuration syntax.
Apache module

Apache is a modular server with two compilation methods:

*
Static Compilation: one-time compilation of core modules and required modules
O
Advantage: Fast Running
O
Disadvantage: to add or delete modules, you must recompile the entire Apache
*
Dynamic Compilation: only the core module and DSO (dynamic shared object) module are compiled-mod_so
O
Advantage: Each module can be compiled independently and loaded with the LoadModule command at any time. commands for specific modules can be used Include commands to make them take effect conditional.
O
Disadvantage: relatively slow running speed

Apache in Ubuntu is dynamically compiled. Configure the module in Ubuntu:

1.
Modify the configuration file of the relevant modules in the directory of mod-available/as needed
2.
Use the a2enmod command to enable the module. Use the a2dismod command to disable the module.

For example, to enable the rewrite module, run the following command:

Sudo a2enmod rewrite

To disable the cgi Module, run the following command:

Sudo a2dismod cgi

Directive Scope

It is divided by the scope of commands. Apache has two types of commands:

*
Common commands: Common commands are valid for the entire server.
*
Container command: It can be placed in the container to implement additional configurations for specific access resources. It is only valid for specific access resources.

Common Containers in Apache include:

*
And : Used to implement additional configuration for the specified directory
*
And : Used to implement additional configuration for the specified file
*
And : Used to implement additional configuration for the specified URL

*
Containers appear in pairs. All configuration commands used in containers should be placed in <> and, for example:


......


*
All the preceding container commands with "Match" have the same function as the corresponding container commands without "Match", but you can use a regular expression to describe resources.
*
These containers can also be nested for more detailed configuration.

In addition, Apache also supports multiple sites at the same time, known as a virtual host. Placed in The commands in the container are only valid for specific virtual hosts.
Although most commands can be included in any container, special cases are also used. To query the configuration segments that a command can be applied to, you can view the scope items of the command in the Apache manual.
Directory-based configuration file

In addition to the main configuration file, Apache can also use special files distributed in the directory tree of the entire website for decentralized configuration. Such a special configuration file is called a directory-based configuration file. These special files are usually called. htaccess, but you can also use the AccessFileName command to change its name.

Obviously, the directive scope in the directory-based configuration file (. htaccess file) is the directory that stores it and all its subdirectories.

*
The syntax of the. htaccess file is the same as that of the main configuration file. Put in Commands in the container can all appear in the. htaccess file. The specific commands that can appear are determined by the AllowOverride command in the main configuration file.
*
Because each access request from the client to the server reads the. htaccess file, modifications to these files take effect immediately, that is, the server does not need to load or restart the configuration file.

Basic configuration instructions
Server id command

*
ServerName: the server is used to identify its host name and port number.
*
ServerAdmin: the Administrator email address contained in the error message returned from the server to the client.
*
ServerSignature: configure the footer of the page generated by the server (error message, ftp directory list of mod_proxy, mod_info output)
*
ServerTokens: controls the Server's "Server:" whether the response header contains information about the Server's operating system type and compiled module.
*
UseCanonicalName: determines how Apache constructs the SERVER_NAME and SERVER_PORT commands in the URL.

File Location command

*
DocumentRoot: the root directory of the main document tree visible on the network.
*
ErrorLog: location where error logs are stored
*
LockFile: when the value of the AcceptMutex command is fcntl or flock, the location of the lock file used by Apache
*
PidFile: Set the file used by the server to record the PID of the parent process (monitoring process.
*
ScoreBoardFile: a file that stores coordination data. Apache uses scoreboard to communicate between parent and child processes)
*
ServerRoot: Specify the basic directory for Server Installation

Tighten Apache configuration in Ubuntu

For the actual product server, the Apache configuration should be tightened first. Therefore, you can create a new local_configs.conf file in the/etc/apache2/conf. d/directory and add the following Configuration:

/Etc/apache2/conf. d/local_configs.conf

# Set ServerName
ServerName www.jamond.net
# Protect/

# Forbid default access to file system locations
Order Deny, Allow
Deny from all
# Prevent use of. htaccess files in all directories
# Apart from those specifically enabled.
AllowOverride None


# Restrict display of available server information
ServerSignature Off
ServerTokens production

Apache management tools

Apache kit contains many executable programs, some of which are management tools. This section only describes apache2ctl.
Apache2ctl

Apache2ctl is the frontend program of Apache2 server. The administrator can help control the Apache2 background daemon functions.

Apache2ctl script has two operation modes:

*
As a simple front-end program of apache2, set all necessary environment variables, start apache2, and pass all command line parameters.
*
As the SysV initialization script, it accepts simple parameters of a word, such as start, restart, and stop, and translates them into appropriate signals and sends them to apache2.

*
In the Ubuntu Apache2 STARTUP script/etc/init. d/apache2, apache2ctl is called for control.

Apache2ctl has two syntax formats:

Apache2ctl-Parameters
Apache2ctl action options

Command Parameters Using apache2ctl

*
Display apache version

Apache2ctl-v

*
Display apache version and compilation Parameters

Apache2ctl-V

*
Brief description of an available command line option

Apache2ctl-h

*
Output A list of modules that are statically compiled on the server. It does not list the modules Dynamically Loaded using the LoadModule command

Apache2ctl-l

*
Output A list of commands, including the valid parameters and use regions of each command

Apache2ctl-L

*
Only perform a syntax check on the configuration file .. If "-D DUMP_VHOSTS" is specified, the detailed information about the virtual host configuration is displayed.

Apache2ctl-t

*
Displays the settings read and parsed from the configuration file (currently, only the settings of the virtual host are displayed)

Apache2ctl-S

Action options for using apache2ctl

*
Start The apache2 daemon. If it has been started, an error is generated.

Apache2ctl start

*
Stop The apache2 daemon.

Apache2ctl stop

*
Restart the apache2 daemon. If the daemon is not running, start it. Before restarting the daemon, this command automatically checks the configuration file using configtest to ensure that Apache will not die.

Apache2ctl restart

*
Displays a brief status report.

Apache2ctl status

*
Gracefully restart the apache2 background daemon. If the daemon has not been started, start it. It differs from standard restart in that it does not interrupt the currently opened connection or immediately close the log. This means that if you use it in a log rolling script, you must add a real delay before processing the log to ensure that the old log file is closed before being processed. Before restarting the daemon, this command automatically checks the configuration file using configtest to ensure that apache will not die.

Apache2ctl graceful

*
Gracefully stop The apache2 background daemon. It differs from the standard stop in that it does not interrupt the currently opened connection or immediately close the log.

Apache2ctl graceful-stop

*
Execute a configuration file syntax check. It parses the configuration file and reports Syntax OK or specific Syntax error details.

Apache2ctl configtest
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.