The role of Apache virtualhost is to enable one Apache to serve multiple domain names. It is equivalent to a server that has more than N websites. For example:
My Apache server, IP address X. x. x. x. I have two domain names www.tootoogo.org and lp.tootoogo.org. Set these two domain names to direct to X. x. x. x. After the virtual host is set on the Apache server, the Apache server can simultaneously serve the two domain names so that the two domain names direct to different webpages respectively, so one of my servers has two websites at the same time.
Apache virtualhost configuration method:
Add the following content at the end of the httpd. conf file:
Namevirtualhost *: 80
<Virtualhost *: 80>
Serveralias www.tootoogo.org # It seems that this line is unnecessary
Directoryindex index.html index. php
DocumentRoot "/var/www/data1/"
Servername www.tootoogo.org
Errorlog "log/tootoogo-error_log"
Customlog "logs/tootoogo. Access"
</Virtualhost>
<Virtualhost *: 80>
Directoryindex index.html index. php
DocumentRoot/var/www/data2/
Servername lp.tootoogo.org
Errorlog "log/LP. tootoogo-error_log"
Customlog "logs/LP. tootoogo. Access"
</Virtualhost>
In this way, you can use two domain names to resolve to the same IP address but get different pages.
If you want to disable direct access using IP addresses
Namevirtualhost *: 80
Insert the following content after this sentence:
<Virtualhost *: 80>
Servername youripaddress
<Location/>
Order allow, deny
Deny from all
</Location>
</Virtualhost>
Note:
Modify
<Directory "/usr/local/www/apache22/Data">
Is
<Directory "/usr/local/www/apache22/">
Then you can
Use the following directory to place the webpages corresponding to these two domain names.
DocumentRoot/usr/local/www/apache22/data1
DocumentRoot/usr/local/www/apache22/data1
///// // Out-of-the-box ////////////
To listen to other port numbers, you can add
Listen yourip: port, for example, listen 192.168.1.1: 8081, then the corresponding
Namevirtualhost *: 8081 <virtualhost *: 8081>
Servername www.tootoogo.org: 8081
//////////////////////////////////