首页 > 其他分享 >Apache基于IP和端口

Apache基于IP和端口

时间:2024-07-17 09:09:30浏览次数:2  
标签:httpd www etc IP 端口 var html conf Apache

Apache基于IP

步骤1:添加并配置虚拟网卡

  1. 添加虚拟网卡:通常在虚拟机环境中,可以通过虚拟机软件(如VMware或VirtualBox)的网络设置来添加额外的网络适配器。
  2. 配置IP地址:编辑/etc/sysconfig/network-scripts/ifcfg-ethX文件,,并将它们设置为静态IP地址。
vi /etc/sysconfig/network-scripts/ifcfg-ens33
# 内容如下:
DEVICE=ens33
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.10.100
NETMASK=255.255.255.0

vi /etc/sysconfig/network-scripts/ifcfg-ens36
# 内容如下:
DEVICE=ens36
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.10.200
NETMASK=255.255.255.0

image.png

  1. 重启网络服务
systemctl restart network

步骤2:修改Apache配置文件

编辑/etc/httpd/conf/httpd.conf,确保以下行未被注释(即删除#):

IncludeOptional conf.d/*.conf

然后,在/etc/httpd/conf.d/目录下创建两个新的配置文件,比如vhost1.confvhost2.conf,分别用于配置基于IP的虚拟主机:

vim /etc/httpd/conf.d/vhost1.conf
# 内容如下:
<VirtualHost 192.168.10.100:80>
    DocumentRoot "/var/www/html/web1"
</VirtualHost>

vim /etc/httpd/conf.d/vhost2.conf
# 内容如下:
<VirtualHost 192.168.10.200:80>
    DocumentRoot "/var/www/html/web2"
</VirtualHost>

或者写到一个配置文件中

[root@localhost ~]# cat /etc/httpd/conf.d/vhosts-ip.conf
<VirtualHost 192.168.10.100:80>
    DocumentRoot "/var/www/html/web1"
</VirtualHost>
<VirtualHost 192.168.10.200:80>
    DocumentRoot "/var/www/html/web2"
</VirtualHost>

image.png

步骤3:创建目录和主页文件

mkdir -p /var/www/html/web1 /var/www/html/web2
echo "This is my virtual website1." > /var/www/html/web1/index.html
echo "This is my virtual website2 ." > /var/www/html/web2/index.html

重启Apache服务

systemctl restart httpd

步骤4:测试基于IP的虚拟主机

image.pngimage.png

Apache基于端口

步骤5:配置基于端口的虚拟主机

编辑/etc/httpd/conf.d/下的新配置文件,例如vhost3.confvhost4.conf,配置不同的端口:

vim /etc/httpd/conf.d/vhost3.conf
# 内容如下:
Listen 8000
<VirtualHost *:8000>
    DocumentRoot "/var/www/html/web3"
</VirtualHost>

vim /etc/httpd/conf.d/vhost4.conf
# 内容如下:
Listen 8888
<VirtualHost *:8888>
    DocumentRoot "/var/www/html/web4"
</VirtualHost>

或者全部写到一个配置文件中

[root@localhost ~]# cat /etc/httpd/conf.d/vhosts-port.conf 
Listen 8000
<VirtualHost 192.168.10.100:8000>
    DocumentRoot "/var/www/html/web3"
</VirtualHost>
Listen 8888
<VirtualHost 192.168.10.100:8888>
    DocumentRoot "/var/www/html/web4"
</VirtualHost>

步骤6:创建目录和主页文件

mkdir -p /var/www/html/web3 /var/www/html/web4
echo "This is my virtual website3." > /var/www/html/web3/index.html
echo "This is my virtual website4." > /var/www/html/web4/index.html

步骤7:重启Apache服务

systemctl restart httpd

测试基于端口的虚拟主机
再次在Windows系统下使用浏览器访问这两个端口,确保能够看到正确的网页。
image.pngimage.png

标签:httpd,www,etc,IP,端口,var,html,conf,Apache
From: https://www.cnblogs.com/yuanqing09/p/18306534

相关文章

  • TS 入门(四):TypeScript 高级类型与类型操作
    目录前言回顾1.联合类型和交叉类型a.联合类型b.交叉类型2.字面量类型3.类型断言4.类型兼容性5.类型守卫a.`typeof`类型守卫b.`instanceof`类型守卫c.自定义类型守卫扩展知识点:类型映射(MappedTypes)结语前言在前三章中,我们介绍了TypeScript的基础知识......
  • D. The Omnipotent Monster Killer
    D.TheOmnipotentMonsterKillerYou,themonsterkiller,wanttokillagroupofmonsters.Themonstersareonatreewith$n$vertices.Onvertexwithnumber$i$($1\lei\len$),thereisamonsterwith$a_i$attackpoints.Youwanttobattlewithmon......
  • 2024 睿抗机器人开发者大赛CAIP-编程技能赛-本科组(省赛)
    2024睿抗机器人开发者大赛CAIP-编程技能赛-本科组(省赛)RC-u1热҈热҈热҈#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intn,w;cin>>n>>w;intans1=......
  • 端口被占用如何处理Error: listen EADDRINUSE: address already in use :::xxxx
    启动项目出现Error:listenEADDRINUSE:addressalreadyinuse:::9088yarnrunv1.22.19$nodesrc/index.jsevents.js:377thrower;//Unhandled'error'event^Error:listenEADDRINUSE:addressalreadyinuse:::9088atServer.setupL......
  • snipaste最强平替!轻松搞定截图贴图还有OCR文字识别!工作效率提高300%
    Snipaste一直被吐槽没有OCR功能,而且功能也一直没有优化,不少小伙伴都在问有没有类似的平替?当然有啦!小编为您挖到一款超强的国产软件——千鹿设计助手,它堪称是Snipaste的完美平替!目前千鹿设计助手还在不断优化功能,小编这边也要到了注册码:rGUHvi,小伙伴们可以试试,看看下面的......
  • Typescript 中 interface 和 type 的区别
    在TypeScript中,interface​和type​是用来描述对象结构或类型的两种主要方式,它们有一些区别和各自的特点。Interface(接口)定义方式:使用interface​关键字定义,例如:interfacePerson{name:string;age:number;}适用场景:主要用于描述对象的形状(Sh......
  • TS 入门(五):TypeScript接口与类
    目录前言回顾高级类型与类型操作1.接口a.基本接口b.可选属性和只读属性c.函数类型接口d.可索引类型e.接口继承2.类a.基本类b.类的成员(属性和方法)c.构造函数d.继承和派生类e.公有、私有和受保护的修饰符f.静态属性和方法g.抽象类扩展知识点:接口与类的结合......
  • AvalonMM接口Interval Timer IP的寄存器介绍和Interval Timer寄存器读写操作详解
    一、间隔定时器结构间隔定时器的结构框图: 该间隔定时器有如下两个特点:-Avalon-MM接口,提供对6个16位寄存器的访问;-有一个脉冲输出接口(可选),可用作周期性脉冲发生器;该间隔定时器的所有寄存器都是16位的,可兼容16-bit和32-bit处理器。某些寄存器只存在于特定的配置中,例如,当该......
  • windows无法绑定端口,但是使用netstat无法查到占用进程
    windows无法绑定端口,但是使用netstat无法查到占用进程内容来源https://stackoverflow.com/questions/58216537/what-is-administered-port-exclusions-in-windows-10本文章只对该链接内容做简单的提取,总结。如果无法解决建议翻阅原文。windows保留端口查看保留端口。如果你......
  • 文件流下载文件,zip/其他格式文件
         constloading=this.$loading({      lock:true,      text:'下载中...',      spinner:'el-icon-loading'     })     batchDownload(params).then((res)=>{//res格式:{data:二进制文件流......