Apache 虚拟主机配置
开放虚拟主机文件
修改主配置文件 解开注释,使用虚拟主机配置文件。
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 执行命令
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?