ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Apache 虚拟主机配置

2020-03-15 16:07:05  阅读:312  来源: 互联网

标签:虚拟主机 配置文件 local ServerName 配置 vim Apache com


开放虚拟主机文件 修改主配置文件 解开注释,使用虚拟主机配置文件。 vim /usr/local/apache2/conf/httpd.conf
1 Include conf/extra/httpd-vhosts.conf

 

虚拟主机参数详解

<VirtualHost >:指定虚拟主机
 
DocumentRoot:指定URL目录
 
ServerName:指定域名地址
 
CustomLog:指定日志文件
 
Serveradmin:管理员邮箱
 
ServerAlias:域名别名(可写多行)
 
Errorlog:错误日志
 
Customlog:访问日志
 
</VirtualHost>:结尾

虚拟主机配置


  基于IP :使用多个IP 访问不同的资源的虚拟主机 1.创建多个子IP
ifconfig eth0:1 192.168.1.131
ifconfig eth0:2 192.168.1.132
ifconfig eth0:3 192.168.1.133

2.创建多个URL资源

vim 资源路径1/index.html
内容:

vim 资源路径2/index.html
内容:

vim 资源路径3/index.html
内容:

执行命令

3.修改虚拟主机配置文件

vim httpd-vhosts.conf
内容:

# 基于IP虚拟主机1
<VirtualHost 192.168.1.131:80>
    DocumentRoot "/usr/local/html1"
    ServerName 123.com
<Directory "/usr/local/html1">
    Require all granted
</Directory>
</VirtualHost>

# 基于IP虚拟主机2
<VirtualHost 192.168.1.132:80>
    DocumentRoot "/usr/local/html2"
    ServerName 123.com
<Directory "/usr/local/html2">
    Require all granted
</Directory>
</VirtualHost>

# 基于IP虚拟主机3
<VirtualHost 192.168.1.133:80>
    DocumentRoot "/usr/local/html3"
    ServerName 123.com
<Directory "/usr/local/html3">
    Require all granted
</Directory>
</VirtualHost>

配置文件
基于域名使用1个IP绑定多个域名进行多资源访问的虚拟主机 1.修改hosts文件,或者DNS配置域名
文件目录:C:\Windows\System32\drivers\etc\hosts
底行添加内容:

192.168.1.107    www.1.com
192.168.1.107    www.2.com
192.168.1.107    www.3.com

文件修改

2.创建多个URL资源

vim 资源路径1/index.html
内容:

vim 资源路径2/index.html
内容:

vim 资源路径3/index.html
内容:

执行命令

3.修改虚拟主机配置文件

vim httpd-vhosts.conf
内容:



# 基于域名1
<VirtualHost *:80>
    DocumentRoot "/usr/local/html1"
    ServerName www.1.com
<Directory "/usr/local/html1">
    Require all granted
</Directory>
</VirtualHost>

# 基于域名2
<VirtualHost *:80>
    DocumentRoot "/usr/local/html2"
    ServerName www.2.com
<Directory "/usr/local/html2">
    Require all granted
</Directory>
</VirtualHost>

# 基于域名3
<VirtualHost *:80>
    DocumentRoot "/usr/local/html3"
    ServerName www.3.com
<Directory "/usr/local/html3">
    Require all granted
</Directory>
</VirtualHost>

配置文件
基于端口:使用1个IP绑定多个端口进行多资源访问的虚拟主机 1.修改主配置文件添加端口
vim httpd.conf
添加内容:

Listen 801
Listen 802
Listen 803

主配置文件

2.修改虚拟主机配置文件

vim httpd-vhosts.conf
内容:


# 基于端口1
<VirtualHost 192.168.1.107:801>
    DocumentRoot "/usr/local/html1"
    ServerName www.1.com
<Directory "/usr/local/html1">
    Require all granted
</Directory>
</VirtualHost>

# 基于端口2
<VirtualHost 192.168.1.107:802>
    DocumentRoot "/usr/local/html2"
    ServerName www.2.com
<Directory "/usr/local/html2">
    Require all granted
</Directory>
</VirtualHost>

# 基于端口3
<VirtualHost 192.168.1.107:803>
    DocumentRoot "/usr/local/html3"
    ServerName www.3.com
<Directory "/usr/local/html3">
    Require all granted
</Directory>
</VirtualHost>

配置文件

3.重启后查看端口是否开放

netstat -lnp | grep 80
执行结果:


tcp        0      0 :::801                      :::*                        LISTEN      1504/./httpd        
tcp        0      0 :::802                      :::*                        LISTEN      1504/./httpd        
tcp        0      0 :::803                      :::*                        LISTEN      1504/./httpd        

执行命令

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:虚拟主机,配置文件,local,ServerName,配置,vim,Apache,com
来源: https://www.cnblogs.com/liujunjun/p/12498058.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有