热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

Apache搭建多个站点方法详解

Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需要在编辑状态操作,不能像windowsiis直接点击几下就好了。

Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需要在编辑状态操作,不能像windows iis直接点击几下就好了,以下是介绍配置的方法。

最平常的大概有3种方法。

第一种:单IP不同端口

第二种:多IP同端口(独立IP的虚拟空间)

第三种:域名绑定根目录的方式(共享IP的虚拟空间)

Apache的核心配置文件名是”httpd.conf”,其所存放的路径在Apache目录下的conf文件夹下。修改它只需要使用记事本(建议使用其他编辑器,带行数的那种,方便修改),生效的话只需要保存httpd.conf,重启apache即可。

下面多站点支持的话,修改httpd.conf的第187~264行(不同的httpd.conf可能有差异),也就是在ServerAdmin和ServerName那里,大部分是注释。下面是主要修改的地方。

注意:如果是服务器请备份httpd.conf后再修改文件。

  1. # 'Main' server configuration 
  2. # 
  3. # The directives in this section set up the values used by the 'main' 
  4. # server, which responds to any requests that aren't handled by a 
  5.  definition.  These values also provide defaults for 
  6. # any  containers you may define later in the file. 
  7. # 
  8. # All of these directives may appear inside  containers, 
  9. # in which case these default settings will be overridden for the 
  10. # virtual host being defined. 
  11. # 
  12. # 
  13. # ServerAdmin: Your address, where problems with the server should be 
  14. # e-mailed.  This address appears on some server-generated pages, such 
  15. # as error documents.  e.g. admin@your-domain.com 
  16. # 
  17. ServerAdmin admin@example.com 
  18. # 
  19. # ServerName gives the name and port that the server uses to identify itself. 
  20. # This can often be determined automatically, but we recommend you specify 
  21. # it explicitly to prevent problems during startup. 
  22. # 
  23. # If your host doesn't have a registered DNS name, enter its IP address here. 
  24. # 
  25. ServerName www.example.com:80 
  26. # 
  27. # Deny access to the entirety of your server's filesystem. You must 
  28. # explicitly permit access to web content directories in other  
  29.  blocks below. 
  30. # 
  31.  
  32.     AllowOverride All 
  33.     Require all denied 
  34.  
  35. # 
  36. # Note that from this point forward you must specifically allow 
  37. # particular features to be enabled - so if something's not working as 
  38. # you might expect, make sure that you have specifically enabled it 
  39. # below. 
  40. # 
  41. # 
  42. # DocumentRoot: The directory out of which you will serve your 
  43. # documents. By default, all requests are taken from this directory, but 
  44. # symbolic links and aliases may be used to point to other locations. 
  45. # 
  46. DocumentRoot "g:/www" 
  47. "g:/www"
  48.     # 
  49.     # Possible values for the Options directive are "None", "All", 
  50.     # or any combination of: 
  51.     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
  52.     # 
  53.     # Note that "MultiViews" must be named *explicitly* --- "Options All" 
  54.     # doesn't give it to you. 
  55.     # 
  56.     # The Options directive is both complicated and important.  Please see 
  57.     # http://httpd.apache.org/docs/2.4/mod/core.html#options 
  58.     # for more information. 
  59.     # 
  60.     Options Indexes FollowSymLinks 
  61.     # 
  62.     # AllowOverride controls what directives may be placed in .htaccess files. 
  63.     # It can be "All", "None", or any combination of the keywords: 
  64.     #   Options FileInfo AuthConfig Limit 
  65.     # 
  66.     AllowOverride All 
  67.     # 
  68.     # Controls who can get stuff from this server. 
  69.     # 
  70.     Require all granted 
  71.  

第一种一般是测试环境,毕竟加了端口,如何绑定域名,访问的时候域名后面也需加端口。

例子分别通过80和8080访问不同的根目录,大概在50几行有个Listen 80,在下面添加8080端口。

  1. Listen 80 
  2. Listen 8080  
  3.     ServerAdmin admin@myxzy.com  
  4.     ServerName localhost:80  
  5.     DocumentRoot "g:/www1"  
  6.      "g:/www1">  
  7.      Options  Indexes FollowSymLinks  
  8.      AllowOverride All  
  9.      Require all granted  
  10.        
  11.   
  12.   
  13.     ServerAdmin admin@myxzy.com 
  14.     ServerName localhost:8080   
  15.     DocumentRoot "g:/www2"  
  16.    "g:/www2">  
  17.      Options Indexes FollowSymLinks  
  18.      AllowOverride All  
  19.      Require all granted  
  20.            
  21.  

第二种多IP同端口。

IP地址1:192.168.2.2  IP地址2:192.168.1.68  端口同是80端口。

  1.   
  2.     ServerAdmin admin@myxzy.com  
  3.     ServerName localhost:80  
  4.     DocumentRoot "g:/www1"  
  5.      "g:/www1">  
  6.      Options FollowSymLinks  
  7.      AllowOverride All  
  8.      Require all granted  
  9.        
  10.   
  11.   
  12.     ServerAdmin admin@myxzy.com 
  13.     ServerName localhost:80  
  14.     DocumentRoot "g:/www2"  
  15.    "g:/www2">  
  16.      Options FollowSymLinks  
  17.      AllowOverride All  
  18.      Require all granted  
  19.            
  20.  

第三种同IP不同域名和根目录(域名的话修改本地host演示)。

  1.   
  2.     ServerAdmin admin@myxzy.com  
  3.     ServerName www.hzhuti.com  
  4.     DocumentRoot "g:/www1"  
  5.      "g:/www1">  
  6.      Options FollowSymLinks  
  7.      AllowOverride All  
  8.      Require all granted  
  9.        
  10.   
  11.   
  12.     ServerAdmin admin@myxzy.com 
  13.     ServerName www.111cn.net 
  14.     DocumentRoot "g:/www2"  
  15.    "g:/www2">  
  16.      Options FollowSymLinks  
  17.      AllowOverride All  
  18.      Require all granted  
  19.            
  20.  


推荐阅读
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
  • 本文介绍了一个免费的asp.net控件,该控件具备数据显示、录入、更新、删除等功能。它比datagrid更易用、更实用,同时具备多种功能,例如属性设置、数据排序、字段类型格式化显示、密码字段支持、图像字段上传和生成缩略图等。此外,它还提供了数据验证、日期选择器、数字选择器等功能,以及防止注入攻击、非本页提交和自动分页技术等安全性和性能优化功能。最后,该控件还支持字段值合计和数据导出功能。总之,该控件功能强大且免费,适用于asp.net开发。 ... [详细]
  • Skywalking系列博客1安装单机版 Skywalking的快速安装方法
    本文介绍了如何快速安装单机版的Skywalking,包括下载、环境需求和端口检查等步骤。同时提供了百度盘下载地址和查询端口是否被占用的命令。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
author-avatar
珠珠VS胖胖
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有