Apache default virtual host
step:
Edit the apache configuration file vim /usr/local/apache2.4.33/conf/httpd.conf and remove the # to make the virtual host configuration file take effect
Open the virtual host configuration file vim /usr/local/apache2.4.33/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected] //管理员邮箱,可以删除
DocumentRoot "/usr/local/apache2.4.33/docs/dummy-host.example.com"//网站的根目录
ServerName dummy-host.example.com //域名
ServerAlias www.dummy-host.example.com//别名,可以写多个
ErrorLog "logs/dummy-host.example.com-error_log"//错误日志
CustomLog "logs/dummy-host.example.com-access_log" common//访问日志
</VirtualHost>
Modify a configuration information
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/abc.com"
ServerName abc.com
ServerAlias www.abc.com www.ceshi.com
ErrorLog "/logs/abc.com-error_log"
CustomLog "logs/abc.com-access_log" common
</VirtualHost>
Create the file defined above
mkdir /data/wwwroot
mkdir /data/wwwroot/abc.com
mkdir /logs
touch /logs/abc.com-access_log
touch /logs/abc.com-error_log
vim /data/wwwroot/abc.com/index.php//编辑php页面,简单写一个echo hello测试就行
Test configuration file syntax, reload.
Test with curl -x, (if you don't use curl, it will link to the external network abc.com)
[root@glinux-01 logs]# curl -x192.168.244.128:80 abc.com
this is abc[root@glinux-01 logs]#
(Note that if you visit any link in the current state, you will visit abc.com, because abc is defined in the virtual host configuration file as the default)