The access mechanism of HTTPD virtual host and its log definition

Source: Internet
Author: User

Note: Turn off the firewall, SELinux

VirtualHost Definition:

Based on IP address virtualhost:

Edit httpd.conf File:

#DocumentRoot "/web/html" #注释主服务配置

Below to establish a virtual host, if you do not edit the virtual host in the httpd.conf file, you can also create a new virtual host file to work.

Create a new virtual host configuration file under/etc/httpd/conf.d/

Vim/etc/httpd/conf.d/virtualhost.conf

Edit

<virtualhost 10.140.165.169:80> #指定iip地址和端口
ServerName www.izyno.com #指定主机名
DocumentRoot "/www/izyno.com" #指定主机根目录, you need to create a new.
</VirtualHost>

<virtualhost 10.140.165.170:80>
ServerName Www.51cache.top
DocumentRoot "/www/51cache.top"
</VirtualHost>

To create a new host root directory and edit the home page file:

[[email protected] ~]# Mkdir/www/{izyno.com,51cache.top}

Specify the NIC alias IP address:

[[Email protected] ~]# IP addr add 10.140.165.170/24 dev eth0

Test:


Port-based VirtualHost:

Edit the virtualhost.conf file to add the following:

<virtualhost 10.140.165.170:8080> #指定端口
ServerName www.51cache.org
DocumentRoot "/www/51cache.org"
</VirtualHost>

To add a listening port to the httpd.conf file:

Listen 8080 Port

Test:

Host name-based virtualhost:

Edit the Virtualhost.conf file to add:

<virtualhost 10.140.165.169:80>
ServerName www.b.com
DocumentRoot "/www/b.com"
</virtualhost

Mkdir/www/b.com

Vim index.html

Set up the Windows Hosts file or set up DNS, where the Hosts file is set:

10.140.165.169 www.b.com
10.140.165.169 www.izyno.com

The following warning appears for restarting the HTTPD service:

Starting httpd: [Mon Oct 10:50:06] [warn] VirtualHost 10.140.165.169:80 overlaps with VirtualHost 10.140.165.169:8 0, the first have precedence, perhaps you need a namevirtualhost directive
[Mon Oct 10 10:50:06 2016] [Warn] Namevirtualhost *:80 has no virtualhosts

Note: The above means that the current virtual host is not configured with a domain-based virtual host. Multiple file directories that point to the same IP address will be overwritten by the first name. This means that access to xxx.com or yyy.com will be turned to xxx.com.

Need to add: Namevirtualhost 10.140.165.169:80 in virtualhost.conf

Test:

Complete.

VirtualHost access mechanism definition:

Define the izyno.com host user access authentication mechanism:

Edit virtualhost.conf:

<virtualhost 10.140.165.169:80>
ServerName www.izyno.com
DocumentRoot "/www/izyno.com"
<directory "/www/izyno.com" >
Options None
AllowOverride authconfig #允许使用与认证授权相关的指令, they include Authdbmgroupfile authdbmuserfile authgroupfile authname Authtypeauthuserfile and require
AuthType Basic
AuthName "My Site."
AuthUserFile "/ETC/HTTPD/.HTPASSWD" #指定用户认证文件, you need to use htpasswd generation.
Require Valid-user #定义为所有认证用户可以访问
</Directory>
</VirtualHost>

Build users with HTPASSWD: Two users were created here, Tom and Jory.

HTPASSWD–C–M/ETC/HTTPD/.HTPASSWD Tom #-c You need to add the first time you create, and the second time you create the.-M, use the MD5 format to encrypt the password.

Test:

can be accessed, of course, for a user setting or a group.

To set access permissions for a network segment or a fixed IP address:

Edit the virtualhost.conf file to add the following:

<virtualhost 10.140.165.170:80>
ServerName Www.51cache.top
DocumentRoot "/www/51cache.top"
<directory "/www/51cache.top" >
Options None
allowoverride None
Order Deny,allow
Deny from 10.140.165.93 #拒绝93IP进行访问, if a network segment can also be added as: The 10.140.165.0/24,allow mechanism is no longer supported in 2.4.
</Directory>
</VirtualHost>

Test:

To set the VirtualHost logging mechanism:

Edit the virtualhost.conf file to add logging capabilities:

<virtualhost 10.140.165.169:80>
ServerName www.izyno.com
DocumentRoot "/www/izyno.com"
Customlog/var/log/httpd/izyno.com/access_log combined #添加日志记录, you'll need to create a new izyno.com file.
<directory "/www/izyno.com" >
Options None
AllowOverride authconfig
AuthType Basic
AuthName "My Site."
AuthUserFile "/ETC/HTTPD/.HTPASSWD"
Require Valid-user
</Directory>
</VirtualHost>

New Log directory:

Mkdir/var/log/httpd/{izyno.com,b.con,51cache.top,51cache.org}–pv

Test:

Client Access B.Com, view the logs generated by B.Com:

[[email protected] b.com]# ls
Access_log
[email protected] b.com]# cat Access_log
10.140.184.166--[10/oct/2016:12:34:37 +0800] "get/http/1.1" "-" "mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; trident/7.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729;. net4.0c;. net4.0e; infopath.3) "
10.140.184.166--[10/oct/2016:12:34:37 +0800] "Get/favicon.ico http/1.1" 404 284 "-" "mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; trident/7.0; SLCC2;. NET CLR 2.0.50727;. NET CLR 3.5.30729;. NET CLR 3.0.30729;. net4.0c;. net4.0e; infopath.3) "

Complete the logging mechanism.

The default page jump does not exist on the page where the access is set:

Add a default jump in virtualhost.conf:

<virtualhost 10.140.165.169:80>
ServerName _default_
DocumentRoot "/www/default"
</VirtualHost>

New default/index.html

Test:


Apache logs are many and miscellaneous, if you rely on the analysis of logs or check the server process to monitor Apache running state, more cumbersome. In fact, in the Apache 1.3.2 and later version of a feature module to view the Apache status Server-status

Define the location server-status mechanism:

Edit the httpd.conf file to cancel the following # comment.

<Location/server-status>
SetHandler Server-status
Order Allow,deny
Allow from 10.140.184.166
</Location>

Test: Access at 10.140.184.166:

This is a complete server-status configuration.
The first line of Ccvita-server-status indicates that it can be accessed later with a similar http://www.ccvita.com/ccvita-server-status, while
Http://www.ccvita.com/ccvita-server-status?refresh=N will indicate that the Access Status page can be automatically refreshed every n seconds;
Deny from represents a forbidden access address;
Allow from represents the allowed address access;
Extendedstatus on indicates that detailed request information can be seen at the time of the visit, and that the setting can only be used for global settings and cannot be turned on or off in a specific virtual host. Enabling extended state information will cause the server to run less efficiently.

Access under 10.140.165.93:

Complete.

The access mechanism of HTTPD virtual host and its log definition

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.