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

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

找到下面虚拟主机引入的配置文件
CentOS 7.2 Apache2.4配置多虚拟主机 架设多个网站_第1张图片

CentOS 7.2 Apache2.4配置多虚拟主机 架设多个网站_第2张图片


1、多个ip配置

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


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


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

2、端口配置

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

CentOS 7.2 Apache2.4配置多虚拟主机 架设多个网站_第3张图片


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


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

测试

CentOS 7.2 Apache2.4配置多虚拟主机 架设多个网站_第4张图片


3、配置主机名

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


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



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

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

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

这里写图片描述

你可能感兴趣的:(Linux服務器)