基于多IP地址Web服务
【Centos7.4版本】
!!!测试环境我们首关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# setenforce 0
一、配置多IP地址Web服务
1、首先先看一下本地网卡的信息
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cat ifcfg-ens32
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=10.0.0.129 //我本机主网卡P地址
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32
UUID=e4b11756-1775-4b6a-adbf-95f3f24f941e
DEVICE=ens32
ONBOOT=yes
2、我们使用ens32网卡作为主网卡,然后复制一个子网卡ens32:2(子网卡冒号后面的数字代表子网卡的编号,可任意取)
[root@localhost network-scripts]# cp ifcfg-ens32 ifcfg-ens32:2
3、编辑子网卡的配置信息
[root@localhost network-scripts]# vim ifcfg-ens32:2
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=10.0.0.22 //改与主网卡同网段的其他地址信息(但不能使用该网段的三个不难使用的IP)
NETMASK=255.255.255.0
GATEWAY=10.0.0.2 //我的虚拟机NAT网卡的网关默认的是10.0.0.2
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32:2 //名字可改也可以不改,影响不大
UUID=e4b11756-1775-4b6a-adbf-95f3f24f941e
DEVICE=ens32:2 //块设备的名字必须改成子网卡的名字
ONBOOT=yes
4、重启网络服务,查看网卡配置信息
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::fe04:212a:5e53:cec4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:b3:89:a5 txqueuelen 1000 (Ethernet)
RX packets 23547 bytes 29611303 (28.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5069 bytes 654850 (639.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens32:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.22 netmask 255.255.255.0 broadcast 10.0.0.255
ether 00:0c:29:b3:89:a5 txqueuelen 1000 (Ethernet) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 152 bytes 13128 (12.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 152 bytes 13128 (12.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
5、使用YUM安装HTTP服务
[root@localhost ~]# yum install -y httpd
6、启动http服务,设置开机自启
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service
7、查看http监听端口是否开启(监听端口没开的话,后面就访问不了主机信息)
[root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1005/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1387/master
tcp6 0 0 :::80 :::* LISTEN 14164/httpd
tcp6 0 0 :::22 :::* LISTEN 1005/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1387/master
udp 0 0 0.0.0.0:68 0.0.0.0:* 10151/dhclient
udp 0 0 0.0.0.0:15648 0.0.0.0:* 10151/dhclient
udp 0 0 127.0.0.1:323 0.0.0.0:* 722/chronyd
udp6 0 0 :::23051 :::* 10151/dhclient
udp6 0 0 ::1:323 :::* 722/chronyd
8、要编辑多IP的虚拟主机,首先看看配置模板
[root@localhost ~]# rpm -qa | grep http
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-2.4.6-93.el7.centos.x86_64
[root@localhost ~]# vim /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
............ //上面的我省略了
<VirtualHost *:@@Port@@>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost> <VirtualHost *:@@Port@@>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "@@ServerRoot@@/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>
//上面的最后内容就是虚拟主机的配置模板
9、创建每个IP对应的主目录,并写入测试信息
[root@localhost ~]# mkdir /var/www/test1
[root@localhost ~]# mkdir /var/www/test2
[root@localhost ~]# echo '<h1>This host port is 10.0.0.129</h1>' > /var/www/test1/index.html
[root@localhost ~]# echo '<h1>This host port is 10.0.0.22</h1>' > /var/www/test2/index.html
10、编辑http主配置文件,编辑两个<VirtualHost>内容
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
.......... //上面的内容我省略了
<VirtualHost 10.0.0.129:80>
documentroot "/var/www/test1/"
ErrorLog "/var/log/httpd/10.0.0.129-error_log"
CustomLog "/var/log/httpd/10.0.0.129-access_log" common
</VirtualHost> <VirtualHost 10.0.0.22:80>
documentroot "/var/www/test2/"
errorlog "/var/log/httpd/10.0.0.22-error_log"
CustomLog "/var/log/httpd/10.0.0.22-access_log" common
</VirtualHost>
//上面的就是需要添加的虚拟主机配置信息
11、重启httpd服务
[root@localhost ~]# systemctl restart httpd
12、在浏览地址栏分别输入两个IP地址:10.0.0.129和10.0.0.22


基于多IP地址Web服务的更多相关文章
- 基于多主机的Web服务
[Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...
- 如何快速搭建一个基于ServiceStack框架的web服务
ServiceStack是一个高性能的.NET Web Service 平台,能够简化开发高性能的REST (支持JSON,XML,JSV,HTML,MsgPack,ProtoBuf,CSV等消息格式 ...
- Python flask 基于 Flask 提供 RESTful Web 服务
转载自 http://python.jobbole.com/87118/ 什么是 REST REST 全称是 Representational State Transfer,翻译成中文是『表现层状态转 ...
- 基于多端口的Web服务
[Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...
- Spring Cloud Eureka 使用 IP 地址进行服务注册
默认情况下,Eureka 使用 hostname 进行服务注册,以及服务信息的显示,那如果我们使用 IP 地址的方式,该如何配置呢?答案就是eureka.instance.prefer-ip-addr ...
- 基于IIS构建Pyathon Web服务
本文简单叙述了在Windows下,如何利用IIS构建Python Web服务. 其主要步骤如下: 1.在IIS下构建一个站点,如图: 2.配置Python文件的处理程序,如图: 3.最后,在对应站点根 ...
- Web服务器之Nginx详解(理论部分)
大纲 一.前言 二.Web服务器提供服务的方式 三.多进程.多线程.异步模式的对比 四.Web 服务请求过程 五.Linux I/O 模型 六.Linux I/O 模型具体说明 七.Linux I/O ...
- 【转】Web服务器之Nginx详解(理论部分)
大纲 一.前言 二.Web服务器提供服务的方式 三.多进程.多线程.异步模式的对比 四.Web 服务请求过程 五.Linux I/O 模型 六.Linux I/O 模型具体说明 七.Linux I/O ...
- Web 服务编程,REST 与 SOAP(转)
原文地址:Web 服务编程,REST 与 SOAP REST 简介 在开始我们的正式讨论之前,让我们简单看一下 REST 的定义. REST(Representational State Transf ...
随机推荐
- 如何从 dump 文件中提取出 C# 源代码?
一:背景 相信有很多朋友在遇到应用程序各种奇葩问题后,拿下来一个dump文件,辛辛苦苦分析了大半天,终于在某一个线程的调用栈上找到了一个可疑的方法,但 windbg 常常是以 汇编 的方式显示方法代码 ...
- C#中SQLite的使用及工具类
目录 SQLite简介 存储类 亲和类型 引用System.Data.SQLite.dll 软件包分类 使用本机库预加载 常用部署包 工具类 参考资料 SQLite简介 SQLite是一款轻型的数据库 ...
- (九)Struts2模型驱动和属性驱动
出于结构清晰的考虑,应该采用单独的Model实例来封装请求参数和处理结果,这就是所谓的模型驱动, 所谓模型驱动,就是使用单独的JavaBean来贯穿整个MVC流程. 所谓属性驱动,就是使用属性来作为贯 ...
- 记一次metasploitable2内网渗透之1524端口
0x01.漏洞 许多攻击脚本将安装一个后门SHELL于这个端口,尤其是针对SUN系统中Sendmail和RPC服务漏洞的脚本.如果刚安装了防火墙就看到在这个端口上的连接企图,很可能是上述原因.可以试试 ...
- Message Decoding UVA - 213
Some message encoding schemes require that an encoded message be sent in two parts. The fifirst par ...
- 【Azure Developer】使用Java SDK代码创建Azure VM (包含设置NSG,及添加数据磁盘SSD)
在参考Azure官方文档进行VM创建时,发现其中没有包含如何设置NSG的内容,以及如何在创建时就添加数据磁盘的代码(设置磁盘为SSD类型).本文的内容以"使用 Java 创建和管理 Azur ...
- Typora配置PicGo时,提示Failed to fetch【Bug集中营】
Typora配置PicGo时,提示Failed to fetch 两者配置的端口不一致造成的 打开Typora,选择文件-偏好设置-图像-验证图片上传选项,点击验证图片上传选项 会提示错误:Faile ...
- 02- Python的版本
python的官网 https://www.python.org/ Python的版本 python v2.7(2020结束维护) python v.3.5(当前使用的版本) python v3 ...
- Centos7 安装RabbitMQ及配置(亲测)
Rabbit MQ Linux 安装 Centos7 如果是重装先把erlang和rabbitmq卸载干净,不然还会重装失败<rabbitmq和erlang卸载> 记得删除/var/lib ...
- 关于Number、parseInt、isNaN转化参数
1.首先,关于NaN的相等判断 alert(NaN==NaN) //返回的是false: 2.isNaN 确定这个参数是否是数值或者是否可以被转化为数值:NaN是not a number 的缩写,所以 ...