Building Apache Web server Three-scenario simulation of Trilogy

Source: Internet
Author: User
Tags md5 encryption

One, Apache based on port, IP, domain name access to three types of virtual host configuration method
IP and domain name are the same when Port-based
Port and domain name are the same when IP-based
IP and port are the same when domain name is based
1. Port-based
[Email protected] ~]# vim/usr/local/apache2/conf/httpd.conf
Add listening 8080 port

650) this.width=650; "title=" 1.png "src=" Http:// " alt= "Wkiom1uyk47h-9ggaaa6yzaf_yw680.jpg"/>

Turn on child configuration files (secondary virtual host files)

650) this.width=650; "title=" 2.png "style=" Float:none; "src=" Wkiom1uyk8-y6hugaabcpp9_t34382.jpg "alt=" Wkiom1uyk8-y6hugaabcpp9_t34382.jpg "/>

Create the appropriate directory and Web content

650) this.width=650; "title=" 3.png "style=" Float:none; "src=" Wkiol1uylqqwqbb8aahyrsnurwa610.jpg "alt=" Wkiol1uylqqwqbb8aahyrsnurwa610.jpg "/>

Add a virtual Host
Comment out Namevirtualhost *:80

650) this.width=650; "title=" 4.png "style=" Float:none; "src=" Wkiom1uyk9dsya6jaaaisl55lvu640.jpg "alt=" Wkiom1uyk9dsya6jaaaisl55lvu640.jpg "/>

If you do not comment namevirtualhost * 80, the Restart Service will report the following error

650) this.width=650; "title=" 5.png "style=" Float:none; "src=" Wkiol1uylqqqjywraadeacrhooc730.jpg "alt=" Wkiol1uylqqqjywraadeacrhooc730.jpg "/>

The contents of the virtual host are as follows

650) this.width=650; "title=" 6.png "style=" Float:none; "src=" Wkiol1uyltwj6xwyaak5xa6so4u995.jpg "alt=" Wkiol1uyltwj6xwyaak5xa6so4u995.jpg "/>

Client Access
Virtual Host 1

650) this.width=650; "title=" 8.png "style=" Float:none; "src=" Ydjbcaaacffhc9ids116.jpg "alt=" Wkiom1uyk_ydjbcaaacffhc9ids116.jpg "/>

Virtual Host 2

650) this.width=650; "title=" 9.png "style=" Float:none; "src=" Wkiol1uyltfd38sdaacpz0xgejy826.jpg "alt=" Wkiol1uyltfd38sdaacpz0xgejy826.jpg "/>

2. IP-based
Add IP address

650) this.width=650; "title=" 10.png "style=" Float:none; "src=" Wkiom1uyladrl640aarp41pgrwc192.jpg "alt=" Wkiom1uyladrl640aarp41pgrwc192.jpg "/>

Create a new directory and file

650) this.width=650; "title=" 11.png "style=" Float:none; "src=" Wkiol1uylwasvk3naagijo0mhv0013.jpg "alt=" Wkiol1uylwasvk3naagijo0mhv0013.jpg "/>

Configuring a virtual Host
[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

650) this.width=650; "title=" 12.png "style=" Float:none; "src=" Wkiom1uylc6xycrtaakr0omrm-s603.jpg "alt=" Wkiom1uylc6xycrtaakr0omrm-s603.jpg "/>

Client Testing

650) this.width=650; "title=" 13.png "style=" Float:none; "src=" Wkiol1uylwmwmo3jaab37phsoim228.jpg "alt=" Wkiol1uylwmwmo3jaab37phsoim228.jpg "/>


650) this.width=650; "title=" 14.png "style=" Float:none; "src=" Ry5wjaab_pkbmxs4219.jpg "alt=" Wkiom1uylc_ry5wjaab_pkbmxs4219.jpg "/>

3. Domain-based
Create a new directory and file

650) this.width=650; "title=" 15.png "style=" Float:none; "src=" Wkiol1uylwqbegkiaagsuc92rqs783.jpg "alt=" Wkiol1uylwqbegkiaagsuc92rqs783.jpg "/>

Modifying a virtual Host
[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

650) this.width=650; "title=" 16.png "style=" Float:none; "src=" Wkiom1uyleyc284qaaj-vhjtvr4778.jpg "alt=" Wkiom1uyleyc284qaaj-vhjtvr4778.jpg "/>

This line is to enable Namevirtualhost *:80
Otherwise the restart Service will report the following error

650) this.width=650; "title=" 17.png "style=" Float:none; "src=" Wkiol1uylyaxfevaaadp7wsq44s532.jpg "alt=" Wkiol1uylyaxfevaaadp7wsq44s532.jpg "/>

Client Access
Win7 client to do hosts parsing

650) this.width=650; "title=" 18.png "style=" Float:none; "src=" Wkiom1uyle-tvvsmaam5z15db1m550.jpg "alt=" Wkiom1uyle-tvvsmaam5z15db1m550.jpg "/>


650) this.width=650; "title=" 19.png "style=" Float:none; "src=" Wkiol1uylyrcax80aab46v0gbc8881.jpg "alt=" Wkiol1uylyrcax80aab46v0gbc8881.jpg "/>


650) this.width=650; "title=" 20.png "style=" Float:none; "src=" Wkiom1uylfgcxapnaab6hgnyyai568.jpg "alt=" Wkiom1uylfgcxapnaab6hgnyyai568.jpg "/>

When the test is based on one (port, IP, domain name), try to comment out the other two virtual host configuration files to avoid conflicts.
Using a virtual host, be sure to turn on
Include conf/extra/httpd-vhosts.conf in/usr/local/apache2/conf/httpd.conf

For Namevirtualhost in/usr/local/apache2/conf/extra/httpd-vhosts.conf *:80
When Port-based
Comment out #NameVirtualHost *:80
When IP-based
Comment out #NameVirtualHost *:80
When you are based on a domain name
To enable Namevirtualhost *:80
After you change the Apache configuration file, restart the service.

Second, website encryption verification

First make a link to open the appropriate file

650) this.width=650; "title=" 21.png "style=" Float:none; "src=" Wkiol1uylb6bi9esaaj8ua-9vta646.jpg "alt=" Wkiol1uylb6bi9esaaj8ua-9vta646.jpg "/>

Only allow IP for clients to access the Web site, and can only be defined by the user (account password Authentication)

1. Create User and password (Htpasswd–c is to create a file –m password MD5 encryption, when creating a second user should remove-c, otherwise it will overwrite the first user.) For existing users, create again, which is equivalent to updating the password. If you do not have the HTPASSWD command, you can install the Httpd-tools tool or call directly

650) this.width=650; "title=" 22.png "style=" Float:none; "src=" Wkiol1uylb-rhwpvaahvv1bvhzy272.jpg "alt=" Wkiol1uylb-rhwpvaahvv1bvhzy272.jpg "/>

2. Modify the virtual host configuration file
[Email protected] extra]# vim httpd-vhosts.conf

650) this.width=650; "title=" 23.png "style=" Float:none; "src=" Wkiom1uyliwgpapzaahjb2nin-g527.jpg "alt=" Wkiom1uyliwgpapzaahjb2nin-g527.jpg "/>

AuthName Jiami prompts the user for the message "Jiami"
AuthType Basic Identification method is basic
authuserfile/usr/local/apache2/conf/users specifies the path and file name of the authentication user name password
Require valid-user a legitimate user to access (user in the users file above)
Order Allow,deny allow to be rejected first
Allow from only Client access with IP
Note: Require user User1 if you want to make it accessible to some users in user User2
User names are separated by a space and are accessible only to the listed users.
Common code
Require all granted #允许所有
Require all denied #拒绝所有
Require env Env-var [Env-var] ... #允许, match any of the environment variables
Require method Http-method [Http-method] ... #允许, specific HTTP methods
Require expr expression #允许, true
Require user userid [userid] ... #允许, specific users
Require group Group-name [Group-name] ... #允许, specific user groups
Require Valid-user # #允许, active Users
Require IP 172.20 192.168.2 #允许 specific IP

3. Client Access
Win7 Client Access (Win7 client IP is, enter the account password to access.

650) this.width=650; "title=" 24.png "style=" Float:none; "src=" Wkiol1uylchb4wymaaeiaholrqs500.jpg "alt=" Wkiol1uylchb4wymaaeiaholrqs500.jpg "/>

650) this.width=650; "title=" 25.png "style=" Float:none; "src=" Wkiom1uylimxo6zsaad8x8wwyzs270.jpg "alt=" Wkiom1uylimxo6zsaad8x8wwyzs270.jpg "/>

Linux No access (Linux client IP is

650) this.width=650; "title=" 26.png "style=" Float:none; "src=" Wkiol1uylcarytjeaaj_nbgnxzg888.jpg "alt=" Wkiol1uylcarytjeaaj_nbgnxzg888.jpg "/>

This article from "Step by step into the Linux World" blog, reproduced please contact the author!

Building Apache Web server Three-scenario simulation of Trilogy

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.