Learn the principle and configuration of Apache httpd from the shallower to the deeper

Article anti-leech link address: http://jackcui.blog.51cto.com/

 

1. Introduction to apache :

    Apache HTTPD can also be referred to as httpd or Apache for short. It is one of the most widely used web servers on the Internet. The web server provided by Apache is the daemon httpd, which transmits text through the http protocol. By default, it uses the clear text transmission method of port 80. Of course, later, in order to ensure the security and reliability of the data, the encrypted transmission method of 443 was added. The server provided by Apache is also called: patch server. The reason is very simple. It is a highly modular software. To add corresponding functions to it, you only need to add the corresponding module, let its Apache main program load the corresponding module, and the unnecessary modules can also not be loaded, which ensures the simplicity, lightness and efficiency of Apache. When there is a large number of access to a server It is possible to use multiple multiplexing modes to ensure that the server can quickly respond to client requests, such as MPM, port multiplexing technology.

Two, a complete http request

1. http request and response process:

(1) Establish a connection: the client establishes a connection to the server and sends a message, including the corresponding method of requesting resources and the protocol and encoding that the client can support.

(2) The server decides whether to accept the request.

(3) If the server agrees to establish a connection, it will process the request, including access to resources. When accessing resources, a corresponding mapping mechanism is needed to convert the client's URL to the corresponding file in the local directory.

(4) The server constructs a response message after accessing the corresponding resource

(5) Send a response message, the message contains the corresponding status code, and data message

(6) Server record log

(7) The client receives data

Attached example:

[root@177cnode1 ~]# telnet vhost2.jack.com 80
Trying 192.168.20.128...
Connected to vhost2.jack.com.
Escape character is '^]'.
GET /index.html http/1.1  ====>使用GET方法请求服务器端的主页
host:192.168.20.128 ===>host字段不能缺少,但可以是空值,指定服务器的ip地址或域名也可以指定
端口号,请求报文以一个空行结尾,最后键入回车(两次回车)一般浏览器发送请求时会包括能接受的
编码方式,报文长度等
HTTP/1.1 200 OK   ===>回应报文的状态码
Date: Tue, 04 Oct 2016 03:48:47 GMT   ===>回应报文的其它字段
Server: Apache/2.4.6 (CentOS)
Last-Modified: Sun, 02 Oct 2016 08:41:47 GMT
ETag: "16-53dddcc3d4d35"
Accept-Ranges: bytes
Content-Length: 22
Content-Type: text/html; charset=UTF-8
 
this is vhost2's page    ===>网页内容
[root@177cnode1 ~]#

2. Two http connection methods:

(1) Short connection: non-maintained connection

(2) Long connection: keep the connection.

Quantity limit: how many resources

Time limit: how long the longest connection can be maintained

Attached example:

  Create a file ending with .conf under the corresponding directory. The content is as follows keepalive.conf file

[root@177cnode1 conf.d]# pwd
/etc/httpd/conf.d
[root@177cnode1 conf.d]# cat keepalive.conf 
keepalive on
keepalivetimeout 180 
MaxKeepAliveRequests 1000

   The first line in the above configuration enables the keepalive function, the second line sets how many seconds after the connection is established to disconnect the connection, and the third item sets the maximum number of requests to keep alive state to 1000

3. Various server status codes:

  When the server responds to the client, it will respond with the corresponding status code. Different status codes have different meanings.

1xx: Information

2xx: Success category

3xx: Redirection class

4xx: Client error class

5xx: server-side error class

4. Multiple client request methods:

GET、HEAD、POST、PUT、DELETE、OPTION、TRACE …

Attachment: Socket port allocation by IANA organization:

1-1024: well-known port, permanently allocated to fixed applications, is a privileged port, only root has the right to use

1024-4195: Registered port, the requirements are slightly looser, assigned to a certain program for registration

41952-65535: Random port used by the client program, dynamic port, also called private port or random port

Three, the characteristics of http:

Highly modular: core module +modules

1. Multipath processing modules MPM: multipath processing modules

The MPM module is a dynamic shared module in httpd-2.4. It is not compiled as in the main program, and httpd-2. 2 is statically compiled into the main program. In these models, the first prefork model is used by default, and the second model is used less because of errors that cannot be checked. In the third model, because it is a relatively new function, only the version after httpd-2.4 There are some functions, so they are used less, because stability is the kingly way when they are used in the enterprise, not the newer the function, the better

 

prefork: Multi-process model, which is also the default type. It uses pre-derived sub-processes, and uses separate sub-processes to handle different requests, and the processes are independent of each other. Two-level architecture, the main process has several child processes.

 

Several commonly used options (# after the instruction represents the corresponding number of numbers):

These options are directly modified in the main configuration file (httpd-2.2, including before 2.2). In the version after httpd-2.4, the mpm configuration file (/etc/httpd/conf.modules/00-mpm.conf) is written. can

ServerLimit # The upper limit of the number of processes that the server allows to configure. In the other two models, because it is a multi-level architecture, it is related to the product of thread subprocesses, etc.

StartServers # The number of child processes to be started when the httpd service starts

MinspareServers # Create a certain number of processes every one second after the server starts the number of subprocess books specified by StartsServer (it is an exponential increase, 1 for the first time, two for the second time, 4 for the third time, until Stable increase after 32 per second), until it increases to the number specified by MinSpareServer

MaxSpareServers # This value is to set the maximum number of idle processes in the system. Whenever greater than this number, the system will kill some child processes, but when this value is set less than the value of MinSpareServer, the system will automatically set the value to the minimum Number of idle processes plus one

MaxConnectionsPerchild # This value represents the maximum number of connections that each child process can handle and will be killed by the system (because the process may have data errors or memory leaks other than inability during use). If set to 0, it means never kill. This The value is called this name after httpd-2.4

MaxRequestWorkers #Maximum processing limit on the number of concurrent requests. This instruction is only available in versions after 2.4. The meaning is equivalent to MaxClient

MaxClient # MaxClients sets the requests that Apache can process concurrently, and is the parameter that has the greatest impact on Apache performance. The default value of 150 is far from enough. If the total number of requests has reached this value (can be confirmed by ps -ef|grep http|wc -l), then subsequent requests will be queued until a processed request is completed . This is the main reason why there are a lot of system resources left but HTTP access is slow. Although in theory the larger the value, the more requests that can be processed, but Apache's default limit cannot be greater than 256. The ServerLimit command can increase MaxClients without recompiling Apache. This instruction is httpd-2.2

 

worker: Multi-threaded model, one thread is allocated for each request, three-level architecture, one main process, several child processes, and each child process manages several threads

ServerLimit

StartServers

MinSpareThreads

MaxSpareThreads

MaxRequestWorkers should be set to 0, because at this time it is no longer the corresponding user request, 0 means no restriction, no kill

        ThreadsPerChild

event: event-driven model, each process handles multiple requests with multiple processes

ThreadsPerChild

MaxRequestWorkers

        AsyncRequestWorkerFactor

3. Features of httpd:

Virtual host

Reverse proxy

Load balancing

CGI:common Gateway Interface

4. httpd version:

httpd-1.3

httpd-2.0

httpd-2.2

httpd-2.4

In centos6.8, the system version is httpd-2.2, and the httpd version that comes with centos7.0 and later is httpd-2.4

4. Program environment:

1. Main program: /usr/sbin/httpd

2. Remove comment lines and blank lines through regular expressions. The following is an example of the httpd-2.4 version configuration file:

[root@7cnode2 ~]# grep -v -E -e"^[[:space:]]*#" -e "^[[:space:]]*$" httpd.conf

It should be noted here that each configuration in the configuration file is divided into two parts, the configuration command and the value part. The configuration command is not case-sensitive. In addition to the path name, the value part is case-sensitive, and the other parts are also case-insensitive. of!

ServerRoot "/etc/httpd" Configure which location httpd uses to find the configuration file using a relative path. For example, when specifying the error log, it will write a relative path, and look for the error log file storage directory relative to the directory here

Listen 80 listening port, you can listen to multiple ports at the same time, but pay attention to setting selinux and firewall, you can repeat the definition multiple times to listen to multiple ports

Include conf.modules.d/*.conf Load other configuration files, similar to the loading of C language header files. Here you can use relative paths or absolute paths. Relative paths are paths relative to ServerRoot. You can use glob wildcards. , The configuration file here is used to load the DSO (dynamic shared object) module

User apache

Group apache The user name and group name when the program is running. The system account and group account have been created when Apache is installed. The program is started as root when the program is started. After performing all operations with root privileges (for example, start listening on port 80, lower than The 1024 port monitoring requires root to have the power to execute) will execute the program as an unprivileged user

ServerAdmin root@localhost The email address of the administrator. When there is a problem with httpd, contact the email address to contact the administrator

ServerName www.jackcui.node2.com:80 ServerName gives the host name and port number, which is mainly used by the server to identify what its name is. If it is not configured here, the server will query the /etc/hosts file and finally query its own DNS The server will reverse the IP address to the host name. If there is no DNS server, you can also write your own IP address and port number directly. It is strongly recommended that the configuration here is not omitted, otherwise it will be very slow to restart the httpd service, because it will Perform DNS anti-analysis, this configuration is mainly used to define redirection, the server distinguishes whether the domain name accessed is itself or another host

<Directory /> Some configuration of the directory, access permissions for the directory, etc. are all defined here, you can use URL-based definition of access permissions, but you must use

<Location ""> …<Location> to define

    AllowOverride none The AllowOverride parameter is to specify whether the Apache server should look for the .htacess file as the configuration file. If it is set to none, the server will ignore the .htacess file. If it is set to All, then all the instructions in the .htaccess file will be rewritten. write. For AllowOverride, you can also specify the following instruction types that can be overridden.

    Require all denied authorization to the directory here is to deny all access

</Directory>

DocumentRoot "/var/www/html" defines the root location of the directory similar to the root of the configuration file, but here is the root of web page storage. When defining the Directory directory, the directory there can also be an absolute path or relative Path here

<Directory"/var/www">

    AllowOverride None

    Require all granted

</Directory>

<Directory"/var/www/html">

    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted

</Directory>

<IfModule dir_module> is executed here only after the module dir_module is loaded. There can be multiple values ​​after the DirectoryIndex configuration instruction. The sequence is very important. The meaning of the value is which file should be searched when entering the directory when the URL is accessed. When searching in order, find the first one and then find the second value

    DirectoryIndex index.html

</IfModule>

<Files ".ht*"> Disable all security-related sensitive files, such as .htaccess and .htpasswd in the directory

    Require all denied

</Files>

ErrorLog "logs/error_log" set the storage path of the error log, here is a soft link, pointing to the symbolic link /var/log/httpd/

LogLevel warn set the log level, only when this level is reached will the log be recorded

<IfModulelog_config_module> 

The following defines a variety of log recording formats, you can manually modify the format you want to define, the double quotation marks after LogFormat specifically define the format of the log, followed by a name, you can use the following alias when using the defined format Instead, of course, you can directly use double quotes and the corresponding format when you use it, and the access log can also be defined separately in the virtual host

    LogFormat "%h %l %u %t\"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" combined

    LogFormat "%h %l %u %t\"%r\" %>s %b" common

    <IfModule logio_module>

      LogFormat "%h %l %u %t\"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\" %I %O" combinedio

    </IfModule>

The following defines the log, and use the corresponding format as combined

    CustomLog "logs/access_log"combined

</IfModule>

<IfModule alias_module>

ScriptAlias ​​and Alias ​​are similarly defined here. The difference between the two is that ScriptAlias ​​is used as a running file on the server, not a file sent to the client.

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

</IfModule>

<Directory"/var/www/cgi-bin">

    AllowOverride None

    Options None

    Require all granted

</Directory>

<IfModule mime_module>

The mime multimedia Internet mail extension. This module is used to specify content metadata and select the content of the URI or file metadata value in the HTTP response mapping mode. For example, the types in mime-type include language, character set, and encoding

    TypesConfig /etc/mime.types

    AddType application/x-compress .Z

    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml

    AddOutputFilter INCLUDES .shtml

</IfModule>

The following setting adds a charset part to the content-type header of text/plain and text/html resources.

AddDefaultCharset UTF-8

<IfModulemime_magic_module>

    MIMEMagicFile conf/magic

</IfModule>

EnableSendfile on

IncludeOptionalconf.d/*.conf

 

 

3. The difference between httpd-2.2 version and httpd-2.4:

    Most of them are basically the same, but the latter tends to be more modular. The main configuration file is divided for easy configuration and management. The following will talk about the specific differences.

(1) The ServerTokens instruction sets the value of the server HTTP response header field. In version 2.2, in order to protect the server from hacker attacks, the message that the server responds should be displayed in the least detailed form.

(2) The following are some possible assignments of
ServerTokens : ServerTokens Prod displays "Server: Apache"
ServerTokens Major displays "Server: Apache/2"
ServerTokens Minor displays "Server: Apache/2.2"
ServerTokens Min displays "Server: Apache/2.2. 17″
ServerTokens OS displays “Server: Apache/2.2.17 (Unix)”
ServerTokens Full displays “Server: Apache/2.2.17 (Unix) PHP/5.3.5″

(3) PidFilerun/httpd.pid saves the process id of httpd runtime, which is also available in version 2.2

(4) Keepalive definition, version 2.2 is placed in the main configuration file, version 2.4 main configuration file is not defined, the administrator can define a separate configuration file by himself

(5) Prefork module definition, in version 2.2 you can directly edit the main configuration file to define the relevant parameters of the prefork module, version 2.4 in the special module configuration file

 

4. Other configuration files:

  The following three files are the main configuration file and the auxiliary configuration file, as well as the module configuration file. The main configuration file is divided for easy management and will be loaded together when the service is restarted or the configuration file is reloaded.

/etc/httpd/conf/httpd.conf 

/etc/httpd/conf.d/*.conf

/etc/httpd/conf.modules.d/*.conf

The loading format of the module is:

LoadModule module name Module storage path

UnitFile:/usr/lib/systemd/system/httpd.service //Unit file is the system service script startup file of the version after rhel7

 Module file directory:

/usr/lib64/httpd/modules/ 

5. The default root directory of the site master server: /var/www/html

6. Log file: /var/log/httpd/

error_log error log

access_log access log

7. Determine whether the service is normal or not:

ss -tnlp | grep “:80\>”

systemctl status httpd.service

Five, three kinds of virtual host configuration

1. Virtual host based on IP address:

   On the same server, there are multiple IP addresses. Each IP address is responsible for the binding of a virtual host. The host name of each host is different, such as www.vhost1.com www.vhost2.com, which is less used because IP addresses are more precious, and such virtual hosts require a large number of IP addresses.

Configuration example:

(1) Add multiple IP addresses for virtual hosts

[root@cnode6_8conf.d]# ip a |grep 192  //此时eth2有一个IP地址
    inet 192.168.66.142/24 scope global eth2

#Use the ip command to add three temporary IP addresses

[root@cnode6_8conf.d]# ip addr add 192.168.66.143/24 dev eth2
[root@cnode6_8conf.d]# ip addr add 192.168.66.144/24 dev eth2
[root@cnode6_8conf.d]# ip addr add 192.168.66.145/24 dev eth2
[root@cnode6_8conf.d]# ip a | grep 192  //通过查看多了3个IP地址
    inet 192.168.66.142/24 scope global eth2
    inet 192.168.66.143/24 scope globalsecondary eth2
    inet 192.168.66.144/24 scope globalsecondary eth2

(2) Add the configuration file of the virtual host

[root@cnode6_8conf.d]# pwd
/etc/httpd/conf.d
[root@cnode6_8conf.d]# vim virtual.conf
<VirtualHost 192.168.66.143:80> 
    ServerName www.vhost1.com
    DocumentRoot "/testdir/vhost1"
    <Directory"/testdir/vhost1">
             AllowOverride none
             Allow from all
             Order Allow,deny   
    </Directory>   
</VirtualHost>
 
<VirtualHost 192.168.66.144:80>
    ServerName www.vhost2.com
    DocumentRoot "/testdir/vhost2"
    <Directory"/testdir/vhost2">
             AllowOverride none
             Allow from all
             Order Allow,deny   
    </Directory>   
</VirtualHost>

 

(3) Modify the /etc/hosts file (this is not necessary, because there is no DNS server to resolve the domain name, so I have to modify the hosts file for testing!)

[root@cnode6_8conf.d]# grep "^192" /etc/hosts
168.66.143  www.vhost1.com
168.66.144  www.vhost2.com
168.66.145 www.vhost3.com

(4) Add the corresponding directories and files to restart the service test. The added directories and files should be defined by the configuration file. These steps are omitted here, the test result should be to access the corresponding domain name, which will be resolved to the corresponding IP to be able to access the corresponding webpage

 

2. Virtual hosting based on domain name:

  On the same server, there is only one IP address, and different host names are used to access different web content. In the definition of virtual host block, NameVirtualHost needs to be used to declare the IP address to be monitored, which is often used. It should be noted that in the httpd-2.4 version, there is no need to use the NameVirtualHost keyword to specify the listening IP address and port number, and the rest has not changed

(1) Modify the configuration file

 

root@cnode6_8conf.d]# pwd
/etc/httpd/conf.d
[root@cnode6_8conf.d]# vim virtual.conf
NameVirtualHost 192.168.66.142:80 //如果要监听主机所有IP可以使用通配符 *
<VirtualHost192.168.66.142:80>
    ServerNamewww.vhost1.com
    DocumentRoot "/testdir/vhost1"
    <Directory"/testdir/vhost1">
             AllowOverride none
             Allow from all
             Order Allow,deny   
    </Directory>   
</VirtualHost>
 
<VirtualHost192.168.66.142:80>
    ServerNamewww.vhost2.com
    DocumentRoot "/testdir/vhost2"
    <Directory"/testdir/vhost2">
          AllowOverride none
          Allow from all
          Order Allow,deny   
    </Directory>   
</VirtualHost>

 

(2) Modify the /etc/hosts file

[root@cnode6_8 conf.d]# grep 192 /etc/hosts
168.66.143 www.vhost1.com
168.66.143 www.vhost2.com

(3) Test

 Visit different domain names during the test, although it is resolved to the same IP address, but can visit different homepages

3. Virtual hosts based on different ports:

  Under the same IP and the same host name, use different ports to monitor, and you need to add the access port when accessing. Not used much, generally used for intranet testing

(1) Modify the configuration file

[root@cnode6_8conf.d]# cat virtual.conf
Listen 8080   //添加监听的端口
<VirtualHost 192.168.66.142:8080>
    ServerName www.vhost1.com
    DocumentRoot "/testdir/vhost1"
    <Directory"/testdir/vhost1">
          AllowOverride none
          Allow from all
          Order Allow,deny   
    </Directory>   
</VirtualHost>
 
<VirtualHost 192.168.66.142:80>
    ServerName www.vhost1.com
    DocumentRoot "/testdir/vhost2"
    <Directory"/testdir/vhost2">
             AllowOverride none
             Allow from all
             Order Allow,deny   
    </Directory>   
</VirtualHost>

(2) Modify the /etc/hosts file

[root@cnode6_8 conf.d]# grep 192 /etc/hosts
168.66.142 www.vhost1.com

  It should be noted that the default port can not be added in the test, but it must be manually added when accessing ports other than 80. When accessing the same domain name and different port addresses, you can also get different web pages.

 

Six, catalog option instructions and other page definitions of the site

 

1. Commonly used commands in the catalog:

(1) options: used to define the display mode of the resource; followed by a list of "options" separated by blank characters

(2) AllowOverRide: httpd allows the use of hidden files in various directories of web documents. Htaccess access control from the individual; this directive defines which directives can be defined in .htaccess

(3) Require: Define the access of users, groups or IPs for access control

2. Site main page file settings (in the main configuration file):

DirectoryIndex  filename1 filename2 ...

There are multiple files after DirectoryIndex, the default page file name for each directory when visiting. When the first file is not found, the second file is found. The file order is very important!

3. Path alias definition (defined in the alias definition module of the main configuration file)

Alias  /URL/ "/PATH/TO/SOME_DIR/"

Define a path alias for a Url that can be mapped to a directory in the local file system through the URL

4.status page

Used to display the current host running status, snapshots of child processes or threads running

<Location /status>

       SetHandler server-status

       Require all granted

</Location>

ExtendedStatus{On|Off} The extended status setting, it is recommended to turn it off, otherwise it will affect the server performance. It is turned off by default. It does not have this line setting. This line setting is a global setting and cannot be set in the virtual host.

Seven, user authentication and group authentication

   The authentication of the http protocol is implemented by the http protocol to authenticate itself. HTTP authentication can be in the form of plain text or digest algorithm. During authentication, the server responds with a 401, rejecting the client's request, and requires the client to enter the account and password for authentication. The account used by the server for authentication is a virtual account, not an account of the server system. It can be stored in a specific file system or database. Connecting to the database requires a corresponding database module to provide interface support for httpd. Form authentication is authenticated by the server application

1. HTTP user authentication

<VirtualHost 192.168.66.142:80>
ServerName www.vhost.com
DocumentRoot"/vhosts/www1"
    <Directory "/vhosts/www1">
       Options None
       AllowOverride None
       Require all granted
    </DIrectory>
    <Directory"/vhosts/www1/admin">
       OptionsNone
       AllowOverrideNone
       AuthTypebasic
       AuthName"Admin Area, Enter your name/password"
       AuthUserFile"/etc/httpd/conf/.htpasswd"
       Requirevalid-user
    </Directory>
</VirtualHost>

 

Use the command to generate the file:

Authentication file: .htpasswd

htpasswd[OPTIONS]  /PATH/TO/HTPASSWD_FILEUSERNAME [PASSWORD]

 -c: Create a file, you need to add -c when there is no password file, and you don’t need to add it again

 -m: use md5

 -s:Force SHA encryption of the password(insecure)

To create an authentication password for jackcui:

[root@cnode6_8 conf.d]# htpasswd -c -s/var/www/html/.htpasswd jackcui
New password:   //输入该用于的密码
Re-type new password:   //再次确认密码
Adding password for user jackcui  //提示添加密码成功

2. HTTP protocol group authentication

<Directory"/vhosts/www1/admin">
    Options None
    AllowOverride None
    AuthType basic
    AuthName "Admin Area, Enter yourname/password"
    AuthUserFile"/etc/httpd/conf/.htpasswd"
    AuthGroupFIle"/etc/httpd/conf/.htgroup"
    Require group 
</Directory>

 

Group account file format: one group definition per line:

group_name: user1 user2 ...

 

8. httpd access log and error log:

   The httpd log can be defined in the main configuration file or separately in each virtual host. The scope is within the defined virtual host block definition range. The logs directory pointed to by the main configuration file is a soft link of /var/logs/httpd. You can specify a separate disk by yourself to improve system performance. The configuration should pay attention to the access permissions of the file directory

[root@7cnode2 conf.d]# cat virtualhost.conf 
<VirtualHost 192.168.20.129:80>
    ServerName vhost.jack.com
    DocumentRoot /vhost/vhost1
<Directory "/vhost/vhost1">
    options none
    AllowOverride none
    require all granted
</Directory>
    ErrorLog "/testdir/vhostlog/error.log"
    CustomLog "/testdir/vhostlog/custom.log"  common
</VirtualHost>

Restart the service to generate a file in the corresponding directory, which can be recorded in the file after access

[root@7cnode2 conf.d]# systemctl restart httpd
[root@7cnode2 conf.d]# curl vhost.jack.com
this is vhost1's test page
[root@7cnode2 conf.d]# tail /testdir/vhostlog/custom.log 
192.168.20.129 - - [06/Oct/2016:17:36:12 +0800] "GET / HTTP/1.1" 200 27

The log format can also be defined by yourself

<VirtualHost 192.168.20.129:80>
        ServerName vhost.jack.com
        DocumentRoot /vhost/vhost1
<Directory "/vhost/vhost1">
        options none
        AllowOverride none
        require host 127.0.0.1   //改为仅本机允许访问,可以测试是否能产生错误日志
</Directory>
        LogFormat "%h %l \"%{User-Agent}i\"" myformat  //自己定义的错误日志的格式
        ErrorLog "/testdir/vhostlog/error.log"
        CustomLog "/testdir/vhostlog/custom.log"  myformat  //定义路径和使用的格式
</VirtualHost>
[root@7cnode2 conf.d]# systemctl restart httpd
[root@7cnode2 conf.d]# cat /testdir/vhostlog/error.log
[Thu Oct 06 17:51:23.474098 2016] [authz_host:error] [pid 37261] [client 192.168.20.1:65376] AH01753: access check of '127.0.0.1' to /noindex/css/fonts/Light/OpenSans-Light.ttf failed, reason: unable to get the remote host name, referer: http://192.168.20.129/noindex/css/open-sans.css
[Thu Oct 06 17:51:23.474185 2016] [authz_core:error] [pid 37261] [client 192.168.20.1:65376] AH01630: client denied by server configuration: /vhost/vhost1/noindex, referer: http://192.168.20.129/noindex/css/open-sans.css
[root@7cnode2 conf.d]# cat /testdir/vhostlog/custom.log 
192.168.20.129 - - [06/Oct/2016:17:36:12 +0800] "GET / HTTP/1.1" 200 27
192.168.20.129 - "curl/7.29.0"
192.168.20.1 - "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0"
192.168.20.1 - "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0"
[root@7cnode2 conf.d]#

Attachment: The format of the access log:

LogFormat: used to define the log format

CustomLog: Define the location and log format of the access log.

 

Common format:

%h The host name of the remote host. The default record is the IP, and HostnameLookups is off by default. If it is changed to on, the server will reverse the client's IP to a domain name, and then check whether it is the corresponding IP in the correct solution

When %l is used with the supporting server to support authentication, record the remote login name

%u http protocol implements protocol authentication challenge when establishing http request

 

%t The time when the request was received, in the format [18/Sep/2011:19:18:28 -0400]

%r first request

%b request size including http header

%s status, for internally redirected requests, this is the original request status, use %>s to record the final status

%{VARNAME}i records the value of the character string headed by the VARNAME variable. Such as %{Referer}i

For more format values, see:

http://httpd.apache.org/docs/2.4/mod/mod_log_config.html#formats

 

Article anti-hotlink address: http://jackcui.blog.51cto.com/

Guess you like

Origin blog.csdn.net/feikillyou/article/details/112980706