Default virtual host for httpd
One server can access multiple, each Web site is a virtual host;
A httpd service under the running of multiple websites, multiple domain names;
Note: any domain name resolves to this machine, can access the virtual host is the default virtual host, its own machine running site, except;
The DNS or Hosts file defines 192.168.188.2 as www.szl.com www.shu.com www.111.com;
The machine only runs two websites, szl.com and 111.com, and does not run www.shu.com;
When the default virtual host option is turned on, then using www.shu.com will jump directly to the default virtual host, which is the first host site of httpd-vhosts.conf;
Here the first site is szl.com, then www.shu.com will show www.szl.com site content;
Turn on the default virtual host option
vim /usr/local/apache2.4/conf/httpd.conf搜索httpd-vhosts取消注释Include conf/extra/httpd-vhosts.conf
Modify the web host site content
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
Modify Content
<VirtualHost *:80> DocumentRoot "/data/wwwroot/szl.com" ServerName szl.com ServerAlias www.szl.com ErrorLog "logs/szl.com-error_log" CustomLog "logs/szl.com-access_log" common</VirtualHost><VirtualHost *:80> DocumentRoot "/data/wwwroot/111.com" ServerName 111.com ServerAlias www.example.com ErrorLog "logs/111.com-error_log" CustomLog "logs/111.com-access_log" common</VirtualHost>
Note: Here are the two Web site parameters, the first is the default virtual host;
Create two sites szl.com with 111.com
mkdir /data/wwwroot/mkdir /data/wwwroot/szl.commkdir /data/wwwroot/111.comvim /data/wwwroot/szl.comvim /data/wwwroot/111.com
在szl.com文件中输入php页面测试代码<?phpecho “szl.com”?>在111.com文件中输入php页面测试代码<?phpecho “111.com”?>
Error detection and update Apache configuration
/usr/local/apache2.4/bin/apachectl -t/usr/local/apache2.4/bin/apachectl graceful
Test results:
Browser input www.shu.com display content for the www.szl.com site;
Content comments
Virtual Host Content Comments:
DocumentRoot: Represents the site file path
ServerName: Representative website name;
Serveralias: website alias;
Errorlog: Error log path
Customlog: Log Path
Lamp architecture-Set the default host for httpd (server multi-site run settings)