Before: I'm using XAMPP, so the path may be different
Find apache\conf\extra\httpd-vhosts.conf
, if not, please create a new httpd-vhosts.conf file yourself, and in the httpd.conf
Include conf/extra/httpd-vhosts.conf
Namevirtualhost*:80# # If there is no matching servername then the first configuration is selected by default<virtualhost*:80>DocumentRoot"d:/apps/xampp/htdocs/"ServerNamelocalhost # #ErrorLog "Logs/dummy-host2.example.com-error.log" # #CustomLog "Logs/dummy-host2.example.com-access.log" Common</VirtualHost><virtualhost*:80>ServerAdmin[email protected]DocumentRoot"D:/apps/xampp/htdocs/www/cdn"ServerNamecdn.demo.comServeraliascdn.test.com # #ErrorLog "Logs/cdn.demo.com.com-error.log" # #CustomLog "Logs/cdn.demo.com.com-access.log" Common</VirtualHost><virtualhost*:80>ServerAdmin[email protected]DocumentRoot"D:/apps/xampp/htdocs/www/admin"ServerNameadmin.demo.comServeraliasadmin.test.com # #ErrorLog "Logs/admin.demo.com-error.log" # #CustomLog "Logs/admin.demo.com-access.log" Common</VirtualHost>
Modify the host file cdn.demo.com
and admin.demo.com
point to127.0.0.1
After rebooting, we can access the cdn.demo.com
CDN folder under the Apache directory, as well as admin.demo.com
access the Admin folder.
admin.demo.com
And cdn.demo.com
can be different domain names
Note in the httpd-vhosts.conf
The first VirtualHost配置
priority is the highest, and if the requested address VirtualHost配置
is not found in the other, the default point is to the first, which is often referred to as主服务器
VirtualHost *:80 Monitor Any 80-port access
VirtualHost * Listen to any address
VirtualHost 127.0.0.1:80 only listens on 127.0.0.1: Access
VirtualHost can be followed by multiple URLs, separated by a space
ServerAdmin Administrator contact can be ignored when address access errors are now on the page
ServerName the domain name that is mapped to
Serveralias aliases, such as the above, cdn.test.com
can be accessed through aliases cdn.demo.com
DocumentRoot mapping directory, which is the address where the file exists, may cause Apache to fail if the mapping directory does not exist
For additional information including agents, directory permissions and more, please refer to the official documentation
Apache virtual directory enables multiple domain names to be bound to the same IP