Apache server a sample configuration method for IP multiple sites
- 2020-05-14 05:27:54
- OfStack
In many cases, one IP cannot correspond to one site in the daily website release. In the case of IP4, the resources of IP are relatively limited. However, as the most popular Apache naturally takes this situation into account, let's take a look at how the apache server is configured with 1 IP multiple sites.
Find "# Virtual hosts" in httpd.conf and add the following line
ServerName Your domain name
HostNameLookups off
example
NameVirtualHost 192.168.1.104
<VirtualHost 192.168.1.104>
ServerName www.php.com
ServerAdmin test@gmail.com
DocumentRoot /data/www1/
DirectoryIndex index.php index.html index.htm index.shtml
Errorlog /usr/local/apache2/logs/wwwError_log
Loglevel warn
HostNameLookups off
<Directory /data/www1/>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.1.104>
ServerName bbs.php.com
ServerAdmin test@gmail.com
DocumentRoot /data/www2/
DirectoryIndex index.php index.html index.htm index.shtml
Errorlog /usr/local/apache2/logs/bbsError_log
Loglevel warn
HostNameLookups off
<Directory /data/www2/>
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The above examples of IP are all 192.168.1.104, and the domains are www.php.com and bbs.php.com, respectively. Therefore, it can be seen that apahce USES ServerName to identify different sites under the same IP.
In practice, you only need to change the IP192.168.1.104 and www.php.com and bbs.php.com to your IP and domain names, respectively.