1.。。基于ip
vi /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.1.142:80>
ServerName 192.168.1.142:80
DocumentRoot /web/upload
<Directory "/web/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/142error.log
CustomLog /var/log/httpd/142access.log combined
</VirtualHost>
<VirtualHost 192.168.1.143:80>
ServerName 192.168.1.143:80
DocumentRoot /var/www/html/upload
<Directory "/var/www/html/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/143error.log
CustomLog /var/log/httpd/143access.log combined
</VirtualHost>
systemctl restart httpd.service
测试
2.。。基于端口
vi /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.1.142:80>
ServerName 192.168.1.142:80
DocumentRoot /web/upload
<Directory "/web/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/142error.log
CustomLog /var/log/httpd/142access.log combined
</VirtualHost>
<VirtualHost 192.168.1.142:8091>
ServerName 192.168.1.142:8091
DocumentRoot /var/www/html/upload
<Directory "/var/www/html/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/143error.log
CustomLog /var/log/httpd/143access.log combined
</VirtualHost>
测试
完成。。
3.。。。基于域名
vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost 192.168.1.142:80>
ServerName www.han.com
DocumentRoot /web/upload
<Directory "/web/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/142error.log
CustomLog /var/log/httpd/142access.log combined
</VirtualHost>
<VirtualHost 192.168.1.142:80>
ServerName www.lei.com
DocumentRoot /var/www/html/upload
<Directory "/var/www/html/upload">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/143error.log
CustomLog /var/log/httpd/143access.log combined
</VirtualHost>
vi /etc/hosts