首页 > 代码库 > apahce配置虚拟主机的3种方法
apahce配置虚拟主机的3种方法
一.基于ip
1) ifconfig 查看自己的网卡接口为enp2s0,
vi /etc/sysconfig/network-scritps/ifc-enp2s0:0
DEVICE="enp2s0:0"
IPADDR=192.168.100.100
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
systemctl restart network
这样就创建好了一个虚拟网卡接口
2)vi /etc/hosts
192.168.200.100 www.virtual1.com
3)在/etc/httpd/conf/httpd.conf里面 加上
Include /etc/httpd/conf/virtualhost/virtual1.conf
mkdir /var/www/html/virtual1 #virtual1的DocumentRoot目录
cd /etc/httpd/conf && mkdir virtualhost && cd virtualhost && touch virtual1.conf #virtual1.conf的配置文件
cd /etc/httpd/logs && mkdir virtualhost #这个目录用来存放virtual1的日志文件
4)vi /etc/httpd/conf/virtualhost/virtual1.conf
<VirtualHost 192.168.100.100:80>
ServerName www.virtual1.com
ServerAlias www.virtual1.com.cn #别名
DocumentRoot /var/www/html/virtual1
DirectoryIndex virtual1.html
ErrorLog /etc/httpd/logs/virtualhost/error_virtual1_log
CustomLog /etc/httpd/logs/virtualhost/access_virtual_log combined
<Directory /var/www/html/virtual1>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
ok了
二.基于主机名
1)
本文出自 “12208412” 博客,请务必保留此出处http://12218412.blog.51cto.com/12208412/1883043
apahce配置虚拟主机的3种方法