【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

一、基于多主机的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、安装HTTP服务,并启动服务

[root@localhost ~]# yum install -y httpd
[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.

3、首先看一下配置模板

[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>
//这几行是配置虚拟主机的模板

4、创建目录,写入测试首页

[root@localhost ~]# mkdir /var/www/aaa
[root@localhost ~]# mkdir /var/www/bbb
[root@localhost ~]# echo '<h1>This servername is aaa.test.com</h1>' > /var/www/aaa/index.html
[root@localhost ~]# echo '<h1>This servername is bbb.test.com</h1>' > /var/www/bbb/index.html

5、在本地的/etc/hosts文件下写入两个hostname

[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.129 aaa.test.com
10.0.0.129 bbb.test.com
//最后两条需要手动添加

6、编辑HTTP的配置文件,添加以下内容

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
.......... //上面的我就省略
<VirtualHost 10.0.0.129:80>
documentroot "/var/www/aaa"
servername "aaa.test.com"
ErrorLog "/var/log/httpd/aaa.test.com-error_log"
CustomLog "/var/log/httpd/aaa.test.com-access_log" common
</VirtualHost>
<VirtualHost 10.0.0.129:80>
documentroot "/var/www/bbb"
servername "bbb.test.com"
ErrorLog "/var/log/httpd/bbb.test.com-error_log"
CustomLog "/var/log/httpd/bbb.test.com-access_log" common
</VirtualHost>
//在文件的最后添加上面的内容

7、重启HTTP服务

[root@localhost ~]# systemctl restart httpd

8、在本地C盘的C:\Windows\System32\drivers\etc\hosts这个文件添加两行内容

 1 # Copyright (c) 1993-2009 Microsoft Corp.
2 #
3 # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
4 #
5 # This file contains the mappings of IP addresses to host names. Each
6 # entry should be kept on an individual line. The IP address should
7 # be placed in the first column followed by the corresponding host name.
8 # The IP address and the host name should be separated by at least one
9 # space.
10 #
11 # Additionally, comments (such as these) may be inserted on individual
12 # lines or following the machine name denoted by a '#' symbol.
13 #
14 # For example:
15 #
16 # 102.54.94.97 rhino.acme.com # source server
17 # 38.25.63.10 x.acme.com # x client host
18
19 # localhost name resolution is handled within DNS itself.
20 # 127.0.0.1 localhost
21 # ::1 localhost
22
23 10.0.0.129 aaa.test.com
24 10.0.0.129 bbb.test.com
25 //添加最后两行就行

9、在浏览器的地址栏分别输入两个域名

基于多主机的Web服务的更多相关文章

  1. 如何快速搭建一个基于ServiceStack框架的web服务

    ServiceStack是一个高性能的.NET Web Service 平台,能够简化开发高性能的REST (支持JSON,XML,JSV,HTML,MsgPack,ProtoBuf,CSV等消息格式 ...

  2. Python flask 基于 Flask 提供 RESTful Web 服务

    转载自 http://python.jobbole.com/87118/ 什么是 REST REST 全称是 Representational State Transfer,翻译成中文是『表现层状态转 ...

  3. 基于多IP地址Web服务

    [Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...

  4. 基于多端口的Web服务

    [Centos7.4版本] !!!测试环境我们首关闭防火墙和selinux [root@localhost ~]# systemctl stop firewalld [root@localhost ~ ...

  5. 基于IIS构建Pyathon Web服务

    本文简单叙述了在Windows下,如何利用IIS构建Python Web服务. 其主要步骤如下: 1.在IIS下构建一个站点,如图: 2.配置Python文件的处理程序,如图: 3.最后,在对应站点根 ...

  6. Web 服务编程,REST 与 SOAP(转)

    原文地址:Web 服务编程,REST 与 SOAP REST 简介 在开始我们的正式讨论之前,让我们简单看一下 REST 的定义. REST(Representational State Transf ...

  7. Rest风格WEB服务(Rest Style Web Service)的真相

    http://blog.csdn.net/jia20003/article/details/8365585 Rest风格WEB服务(Rest Style Web Service)的真相 分类: J2E ...

  8. Webservices-1.web服务定义简介

    一.WEB服务定义(摘自维基百科)详情:http://zh.wikipedia.org/wiki/Web%E6%9C%8D%E5%8A%A1 Web服务是一种服务导向架构的技术,通过标准的Web协议提 ...

  9. 利用python httplib模块 发送Post请求测试web服务是否正常起来!

    最近在学习python,恰好老大最近让我搞个基于post请求测试web服务是否正常启用的小监控,上网查了下资料,发现强大的Python恰好能够用上,所以自己现学现卖,顺便锻炼下自己. 由于本人也刚接触 ...

随机推荐

  1. kali 2019-4中文乱码解决方法

    1.更换阿里源 编辑源,apt-get update && apt-get upgrade && apt-get clean ,更新好源和更新软件 #阿里云deb ht ...

  2. 基于sinc的音频重采样(二):实现

    上篇(基于sinc的音频重采样(一):原理)讲了基于sinc方法的重采样原理,并给出了数学表达式,如下:                  (1) 本文讲如何基于这个数学表达式来做软件实现.软件实现的 ...

  3. JAVA JNI 中解决在C/C++跨线程FindClass失败

    在JAVA与C/C++交互时使用JNI接口: 先是在JAVA调用的C++方法中直接测试FindClass,使用获取到的jclass操作没有任何问题: 但是在调用的C++方法中起线程后,在线程中Find ...

  4. JAVAEE_Servlet_11_GetAndPost

    Get请求和Post请求 * Get请求 和 Post请求各方面分析 - 什么情况下浏览器发送的是Get请求? 1. 通过浏览器的地址栏输入地址,所访问的URL都是get请求,如果以post定义,那么 ...

  5. @valid和自定义异常

    @valid和自定义异常 问题的产生: 当有很多参数需要校验时,比如name,age,email等很多参数都需要判空,或者有长度限制时,如果后端写很多if-else就有很多代码,不美观,不优雅.前端每 ...

  6. ES系列(四):http请求分发框架解析

    上一篇讲解了es的网络通信模块实现过程,大致明白其工作原理.再总结一下,就是基于netty编程范式,形成es通信基础.从而,最终我们得到几个重要的handler: Netty4HttpPipelini ...

  7. 4-socket套接字编程

    socket套接字编程 目标:根据socket模块提供的接口函数,进行组合使用完成基于tcp或者udp的网络编程. 套接字:完成上述目标的一种编程手段,编程方案. 套接字分类: 流式套接字(sock_ ...

  8. 04- HTML常用标签

    HTML标签分类 通过上节博客我们知道了网页的组成:文字 图片 连接 视频 音频.在HTML页面中,带有"< >"符号的元素被称为HTML标签,如上面提到的 <H ...

  9. Centos7 安装RabbitMQ及配置(亲测)

    Rabbit MQ Linux 安装 Centos7 如果是重装先把erlang和rabbitmq卸载干净,不然还会重装失败<rabbitmq和erlang卸载> 记得删除/var/lib ...

  10. C/C++ 介绍的PE文件遍历工具

    在前面的笔记中,我总结了Pe结构的一些结构含义,并手动编写了几段PE结构遍历代码,这里我直接把之前的C语言代码进行了封装,形成了一个命令行版的PE文件查看工具,该工具只有20kb,但却可以遍历出大部分 ...