热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Apache搭建多个站点

如何用Apache搭建的网站系统上运行多个站点呢?最平常的大概有3种方法。第一种:单IP不同端口第二种:多IP同端口(独立I

如何用Apache搭建的网站系统上运行多个站点呢?最平常的大概有3种方法。

第一种:单IP不同端口

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

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

 

下面简单来说这3种方法是如何配置的。

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

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

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

# 'Main' server configuration
#
# The directives in this section set up the values used by the &#39;main&#39; # server, which responds to any requests that aren&#39;t handled by a # definition. These values also provide defaults for # any containers you may define later in the file. # # All of these directives may appear inside containers, # in which case these default settings will be overridden for the # virtual host being defined. # # # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin&#64;your-domain.com # ServerAdmin admin&#64;example.com # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn&#39;t have a registered DNS name, enter its IP address here. # ServerName www.example.com:80 # # Deny access to the entirety of your server&#39;s filesystem. You must # explicitly permit access to web content directories in other # blocks below. # <Directory /> AllowOverride All Require all denied </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something&#39;s not working as # you might expect, make sure that you have specifically enabled it # below. # # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "g:/www" g:/www"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn&#39;t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted Directory>

 

 

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

例子分别通过80和8080访问不同的根目录。

大概在50几行有个Listen 80&#xff0c;在下面添加8080端口。

Listen 80
Listen 8080

*:80> ServerAdmin admin&#64;myxzy.com ServerName localhost:80 DocumentRoot "g:/www1" "g:/www1"> Options Indexes FollowSymLinks AllowOverride All Require all granted *:8080> ServerAdmin admin&#64;myxzy.com ServerName localhost:8080 DocumentRoot "g:/www2" "g:/www2"> Options Indexes FollowSymLinks AllowOverride All Require all granted

 

第二种多IP同端口。

IP地址1&#xff1a;192.168.2.2

IP地址2&#xff1a;192.168.1.68

端口同是80端口。

192.168.1.68:80> ServerAdmin admin&#64;myxzy.com ServerName localhost:80 DocumentRoot "g:/www1" "g:/www1"> Options FollowSymLinks AllowOverride All Require all granted 192.168.2.2:80> ServerAdmin admin&#64;myxzy.com ServerName localhost:80 DocumentRoot "g:/www2" "g:/www2"> Options FollowSymLinks AllowOverride All Require all granted

 

 

第三种同IP不同域名和根目录&#xff08;域名的话修改本地host演示&#xff09;。

 

192.168.2.2:80> ServerAdmin admin&#64;myxzy.com ServerName www.a.com DocumentRoot "g:/www1" "g:/www1"> Options FollowSymLinks AllowOverride All Require all granted 192.168.2.2:80> ServerAdmin admin&#64;myxzy.com ServerName www.b.com DocumentRoot "g:/www2" "g:/www2"> Options FollowSymLinks AllowOverride All Require all granted



推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了如何使用iptables添加非对称的NAT规则段,以实现内网穿透和端口转发的功能。通过查阅相关文章,得出了解决方案,即当匹配的端口在映射端口的区间内时,可以成功进行端口转发。详细的操作步骤和命令示例也在文章中给出。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
author-avatar
jtzhn_146_607
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有