httpd configuration file

Source: Internet
Author: User

MPM: Multi-processing module worker, event (incident-driven model, single-threaded response multi-request),prefork

http://httpd.apache.org/docs/2.4/mpm.html


DSO mechanism: Dynamic shared object, can use LoadModule dynamic loading module, no need to restart service


Example of CentOS 6.5 HTTP configuration file, general default path in /etc/httpd/conf/httpd.conf

There are three main sections configured

Section 1:global Environment

Global configuration and virtual host sharing parameters

Section 2: ' Main ' server configuration

Primary server Configuration

Section 3:virtual Hosts

Virtual Host Configuration

Note: Primary server and virtual host are not used at the same time, the primary server is started by default.

(the value of the parameter needs to be case-sensitive)

Parameters:

Section 1:global Environment
Servertokens OS Display browser system information, etc., generally not enabled
ServerRoot "/ETC/HTTPD" Absolute path definition
Pidfile Run/httpd.pid Relative path definition
KeepAlive on
Whether to support persistent links
Maxkeepaliverequests 100 Maximum number of persistent link requests
KeepAliveTimeout 15 (SEC) Persistent link duration
Timeout 60
TCP Link Timeout duration
<ifmodule prefork.c> Multi-process Model
Startservers 8 Number of idle processes started
Minspareservers 5 Minimum number of idle processes
Maxspareservers 20 Maximum number of idle processes
Serverlimit 256 Limit the maximum number of concurrent requests for users
MaxClients 256 Maximum number of concurrent requests for users
Maxrequestsperchild 4000 The maximum number of requests per child process allowed to process during the life cycle
Role: Do not allow wasted resources to be used as process requests
<ifmodule worker.c> Multithreaded model
Startservers 4 Number of START processes
MaxClients 300 Maximum number of concurrent requests for users
Minsparethreads 25 Minimum number of idle threads
Maxsparethreads 75 Maximum number of idle threads
Threadsperchild 25
How many threads each child process starts
Maxrequestsperchild 0 (no restrictions) Maximum number of processing requests per thread
Listen 80 (multiple can be specified, restart service required)
Default Listener Port
LoadModule Module_alias Path/*.so

Specifying the Load Module
Viewing loaded Modules
[Email protected] ~]# httpd-d dump_modules
Include conf.d/*.conf
Specify the Include path
User Apache
Specify run User
Group Apache Specify a run group
Section 2: ' Main ' server configuration
ServerAdmin [email protected] Admin email Address
ServerName Local Set host name (disabled by default, auto-reverse IP to get host name)
DocumentRoot "/var/www/html" Specify the site root directory
DirectoryIndex Define default Home Page
Errorlog Logs/error_log
Specifying the error log
LogLevel warn (warning message output)
(Debug,info,notice,warn,error,crit,alert,emerg)
Log level
Customlog Logs/access_log Logformat_name (to add a custom format name) Specifying access logs
Logformat variable Logformat_name
Variable
  • %H: Client Address

  • %l: Telnet name, usually-

  • %u: Enter the user name when authentication is not required-

  • %t: time when the server receives a user request

  • %r: Method of requesting a message, etc.

  • %>s: Response Status Code

  • %B: Response message Length (bytes)

  • %{header_name}i: Logs the HTTP protocol header and uses I to represent the value

Note: Keep quotes to be escaped

Define the log format with a variable and set the name

Alias Site Directory Mapping directory

Note: Files in the original site directory will not be accessible after mapping

Path aliases: Mapping the Site Directory
Charset=utf-8

Character




View httpd compiled MPM module

[[email protected] ~]# httpd-lcompiled in MODULES:CORE.C//CORE module PREFORK.C//multi-process module HTTP_CORE.C//used in software or protocol

Site Path Access control

Local File system path

<directory "" > Add to Pattern Matching

Options

    • Indexes No Home page displays the Download list index (recommended) or close with the "-" sign in front

    • FollowSymLinks Tracking Symbol link page (recommended)

    • ...

AllowOverride defines the. htaccess hidden file that defines the access control for the resource directory

    • None not enabled

IP Access Control

Order Allow,deny first allow after deny

Allow from 192.168.0.0/16 allows this network segment IP access before rejecting all IPs

</Directory>

URL access control

<location "" > (available regular, but degraded performance)

</Location>

User Access Control

File access Control-user authentication

  • <directory "File path to control" >

  • Options None option

  • AllowOverride authconfig Allow coverage

  • AuthType Basic Authentication Type

  • AuthName "Admin" certification name

  • Authbasicprovider file authentication provides a path

  • AUTHUSERFILE/ETC/HTTPD/CONF/.HTPASSWD User account password information

  • Require Valid-user (all users) Authenticated users

  • </Directory>

  • Group Certification

  • <directory "File path to control" >

  • Options None

  • AllowOverride authconfig

  • AuthType Basic

  • AuthName "Admin"

  • Authbasicprovider file

  • authuserfile/etc/httpd/conf/.htpasswd

  • AuthGroupFile /etc/httpd/conf/.htgroup

  • Require Group group_name Certification Team name

  • </Directory>


    • HTPASSWD Provide certification documents

    • -C Create a new file for the first time

    • -m MD5 encoded user password

    • -D Delete the specified user


    • Htpasswd-m/etc/httpd/conf/.htpasswd User01

    • Vim/etc/httpd/conf/.htgroup

    • Add Group:user01 User02




Virtual Host: One server provides multiple sites, but you need to cancel the root path of the primary server and then set the virtual server path

#DocumentRoot "/var/www/html"

Based on IP and port

<virtualhost 192.168.1.1:80>

ServerName www.61cto.com

DocumentRoot "/test/a"

Serveralias 61cto

Errorlog "Path"

Customlog "Path"

</VirtualHost>

<virtualhost 192.168.1.2:80>

ServerName www.61cto.com

DocumentRoot "/test/a"

Serveralias 61cto

Errorlog "Path"

Customlog "Path"

</VirtualHost>

<virtualhost 192.168.1.1:80>

ServerName www.61cto.com

DocumentRoot "/test/b"

Serveralias 61cto

Errorlog "Path"

Customlog "Path"

</VirtualHost>

Based on host name

<virtualhost *:80>

ServerName www.71cto.com

DocumentRoot "/TEST/C"

Serveralias 61cto

Errorlog "Path"

Customlog "Path"

</VirtualHost>


Configuration file Syntax check:

Httpd-t

Service httpd Configtest



This article from "Linux_mayi" blog, reproduced please contact the author!

httpd configuration file

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.