CentOS 7.2 Apache2.4配置多虚拟主机 架设多个网站

一、准备工作,修改Apache配置文件

找到下面虚拟主机引入的配置文件
这里写图片描述

这里写图片描述


1、多个ip配置

服务器有多个网卡,每个IP绑定一个站点的方式

<VirtualHost 192.168.13.213:80>
    ServerAdmin [email protected] 
    #放置网站的目录  
    DocumentRoot "/usr/local/soft/apache//htdocs/roobt"  
    #主机名称  
    ServerName one.com  
    #默认访问的页面  
    DirectoryIndex index.html  
    <Directory "/usr/local/soft/apache//htdocs/roobt">  
    Options Indexes FollowSymLinks  
    AllowOverride None  
    Order allow,deny  
    Allow from all
    </Directory>
    #错误日志存放位置  
    ErrorLog "logs/myvirtualhost.com-error.log"  
    CustomLog "logs/myvirtualhost.com-access.log" common  
</VirtualHost> 

<VirtualHost 192.168.13.200:80>
    ServerAdmin [email protected] 
    #放置网站的目录  
    DocumentRoot "/usr/local/soft/apache//htdocs/roobt"  
    #主机名称  
    ServerName two.com  
    #默认访问的页面  
    DirectoryIndex index.html  
    <Directory "/usr/local/soft/apache//htdocs/roobt">  
    Options Indexes FollowSymLinks  
    AllowOverride None  
    Order allow,deny  
    Allow from all
    </Directory>
    #错误日志存放位置  
    ErrorLog "logs/myvirtualhost.com-error.log"  
    CustomLog "logs/myvirtualhost.com-access.log" common  
</VirtualHost> 

2、端口配置

把监听的端口加上,加载Apache的配置文件里

这里写图片描述

<VirtualHost *:80>
    ServerAdmin [email protected] 
    #放置网站的目录  
    DocumentRoot "/usr/local/soft/apache//htdocs/roobt"  
    #主机名称  
    ServerName one.com  
    #默认访问的页面  
    DirectoryIndex index.html  
    <Directory "/usr/local/soft/apache//htdocs/roobt">  
    Options Indexes FollowSymLinks  
    AllowOverride None  
    Order allow,deny  
    Allow from all
    </Directory>
    #错误日志存放位置  
    ErrorLog "logs/myvirtualhost.com-error.log"  
    CustomLog "logs/myvirtualhost.com-access.log" common  
</VirtualHost> 

<VirtualHost *:8080>
    ServerAdmin [email protected] 
    #放置网站的目录  
    DocumentRoot "/usr/local/soft/apache//htdocs/roobt"  
    #主机名称  
    ServerName two.com  
    #默认访问的页面  
    DirectoryIndex index.html  
    <Directory "/usr/local/soft/apache//htdocs/roobt">  
    Options Indexes FollowSymLinks  
    AllowOverride None  
    Order allow,deny  
    Allow from all
    </Directory>
    #错误日志存放位置  
    ErrorLog "logs/myvirtualhost.com-error.log"  
    CustomLog "logs/myvirtualhost.com-access.log" common  
</VirtualHost> 

测试

这里写图片描述


3、配置主机名

vim /etc/hosts;
修改hosts文件 添加如下两行内容
127.0.0.1 one.com
127.0.0.1 two.com

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/soft/apache//htdocs/one"
    ServerName one.com
    DirectoryIndex index.html
    <Directory "/usr/local/soft/apache//htdocs/one">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from All
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/usr/local/soft/apache//htdocs/two"
    ServerName two.com
    DirectoryIndex index.html
    <Directory "/usr/local/soft/apache//htdocs/two">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from All
    </Directory>
</VirtualHost>

为了方便测试,修改我的电脑的host文件

C:\Windows\System32\drivers\etc
加上这句
192.168.13.213 one.com
192.168.13.213 two.com

这里写图片描述

猜你喜欢

转载自blog.csdn.net/post_mans/article/details/79929702