In the previous article, we demonstrated in detail the simple configuration under the httpd virtual host. Today, we will further describe the configuration instances for user authentication based on the previous configuration)
-------- Access to B .org is denied from the address 192.168.1.100 ------
Expected target: Access to www. B .org is denied for 192.168.1.100. Access to other hosts is normal.
Here, we reject access from the local address for verification)
Go to the configuration file to edit the configuration.
# Vim/etc/httpd/conf. d/virtual. conf
650) this. width = 650; "title =" 1..png "src =" http://www.bkjia.com/uploads/allimg/131228/001IH536-0.png "alt =" 185121225.png"/>
# Httpd-t
# Servicehttpdrestart (delete the default welcome. conf so that the experiment results can be clearly verified)
650) this. width = 650; "title =" 2.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IH317-1.png" alt = "185152348.png"/>
Comparison of experiment results:
1. Local access:
650) this. width = 650; "title =" 3.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IL558-2.png" alt = "185217447.png"/>
2. Use the VM to access this address (the VM cannot parse and add a parsing message)
# Vim/etc/hosts
192.168.1.20.www.a.org
192.168.1.20.www. B .org
650) this. width = 650; "title =" 4.png" src = "http://img1.51cto.com/attachment/201310/185355101.png" alt = "185355101.png"/>
# Elinkshttp: // www. B .org
650) this. width = 650; "title =" 5.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IJ505-4.png" alt = "185239235.png"/>
----- Objective to access ----------- based on user authentication -----------
Expected goal: a user must provide a password account to access
Enter the configuration file and make the corresponding configuration editing address www.a.org for verification)
# Vim/etc/httpd/conf. d/virtual. conf
<Directory "/www/a.org">
Optionsnone
AllowOverrideauthconfig -- password of a file
AuthTypebasic -- set the basic user authentication type
AuthName "Restrictarea." -- name setting
AuthUserFile "/etc/httpd/. htpasswd" --- specifies the directory path of the file to be authenticated.
Requirevalid-user --- which users are allowed to specify all of them)
</Directory>
650) this. width = 650; "title =" 6_ .png "src =" http://www.bkjia.com/uploads/allimg/131228/001IMI1-5.png "alt =" 185424252.png"/>
The authenticated user does not create the file specified by the lock. We need to create the file, user and password.
-C needs to be created for the first time.-m specifies the password to be stored as MD5.-D deletes the user)
# Htpasswd-c-m/etc/httpd/. httpasswdtom
# Htpasswd-m/etc/httpd/. httpasswdjerry
# Httpd-t
650) this. width = 650; "title =" 7.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IMM6-6.png" alt = "185444353.png"/>
# Servicehttpdrestart
Verify the experiment results:
Access www.a.org locally
650) this. width = 650; "title =" 8.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IJG2-7.png" alt = "185508535.png"/>
------- Purpose: to return the default page set by the user when accessing the address of a non-existent VM
Expected goals: the default homepage is successfully displayed.
Prerequisites: You must set this parameter at the top of your configuration file)
# Vim/etc/httpd/conf. d/virtual. conf
<VirtualHost192.168.1.107: 80> 4
ServerName_default _
DocumentRoot "/www/default"
</VirtualHost>
650) this. width = 650; "title =" 9.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IK3G-8.png" alt = "185620.20.png"/>
# Mkdir/www/default
# Vim/www/default/index.html
<H1> welcometolinus
# Httpd-t
# Servicehttpdrestart
650) this. width = 650; "title =" 10.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IIP9-9.png" alt = "185638711.png"/>
Lab result Verification
Access 192.168.1.107 locally to view the page
650) this. width = 650; "style =" float: none; "title =" 11.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IL423-10.png" alt = "185703521.png"/>
650) this. width = 650; "style =" float: none; "title =" 12.png" src = "http://www.bkjia.com/uploads/allimg/131228/001IG5A-11.png" alt = "185715847.png"/>
Now the common configuration instances of apache have been completed!
Attaches the configuration file that you edited during the entire configuration.
NameVirtualHost192.168.1.107: 80
<VirtualHost192.168.1.101: 80>
ServerNamehello.magedu.com
DocumentRoot "/www/magedu.com"
</VirtualHost>
<VirtualHost192.168.1.107: 80>
ServerName_default _
DocumentRoot "/www/default"
</VirtualHost>
<VirtualHost192.168.1.107: 80>
ServerNamewww.a.org
DocumentRoot "/www/a.org"
<Directory "/www/a.org">
Optionsnone
AllowOverrideauthconfig
AuthTypebasic
AuthName "Restrictarea ."
AuthUserFile "/etc/httpd/. htpasswd"
Requirevalid-user
</Directory>
</VirtualHost>
<VirtualHost192.168.1.107: 80>
ServerNamewww. B .org
DocumentRoot "/www/B .org"
<Directory "/www/B .org">
Optionsnone
AllowOverridenone
Orderdeny, allow
Denyfrom192.168.1.100
</Directory>
</VirtualHost>
<VirtualHost192.168.1.101: 8080>
ServerNamewww. B .net
DocumentRoot "/www/B .net"
</VirtualHost>
This article is from the "Cola parrot" blog, please be sure to keep this source http://keleyingwu.blog.51cto.com/6621846/1304433