配置apache虚拟主机
- 格式:doc
- 大小:58.50 KB
- 文档页数:8
apache和php的工作流程Apache和PHP是网站服务器中至关重要的两个组件。
Apache是一个开源的Web服务器软件,它主要用于在运行普通网站的服务器上提供网站服务。
而PHP则是一种流行的服务器端脚本语言,它用于在服务器上操作动态网页。
接下来,我们将详细阐述Apache和PHP的工作流程。
1. Apache的工作流程在启动Apache之前,我们需要先配置一些基本的设置,例如监听端口,加载动态链接库和设置虚拟主机(Default 和 Virtual)。
一般而言,Apache会把来自外部网络的请求收集到一个请求队列中,该队列按顺序将所有请求发送到基于当前负载的情况的信材中,这个过程被称为调度。
然后,Apache会根据请求中包含的信息,找到正确的目标文件并向客户端发送响应。
当Apache发送响应时,它可以使用两种不同的方法:静态和动态。
静态响应直接从现有文件系统路径中读取数据并向客户端发送响应。
而动态响应则需要动态生成HTML内容,这通常涉及使用服务器端脚本(例如PHP、CGI或JSP)从数据库或其他数据源中检索数据,并返回需要显示的HTML。
2.PHP的工作流程与Apache一样,启动PHP之前也需要进行一些配置。
这些配置通常包括将PHP解释器与Web服务器集成,定义php.ini和php.errors的路经以及设置PHP的错误报告级别等。
一旦PHP被正确配置,它可以开始接受请求并生成HTML内容。
PHP从Web服务器接收来自客户端的请求,并根据请求参数、Cookies、Session等用户数据访问指定的数据库或文件。
PHP的强大之处在于它具有面向对象的编程,可以完成数据验证、身份验证、表单处理等一系列操作。
当PHP处理请求时,它通常使用以下三个组件:1)PHP解释器–负责编译PHP脚本并执行其内容。
2)PHP模块–处理客户端请求对应的服务器端脚本,生成HTML并将其返回给客户端。
3)PHP库–提供一些常见的函数和类,简化了开发过程。
Date: 18 October 2010Neusoft Institute of InformationLinux基础Date: 18 October 2010Neusoft Institute of Information配置虚拟主机Date: 18 October 2010Neusoft Institute of Information目录• 配置虚拟主机 – 简介 – 基于主机名的虚拟主机的配置 –基于IP的虚拟主机的配置Date: 18 October 2010Neusoft Institute of Information配置虚拟主机—简介一台主机上运行多个WEB站点 一台主机上运行多个 站点 每个站点有自己独立的域名 对用户透明, 对用户透明,好像每个站点都在单独的一台主 机上运行 • 若每个站点的 地址相同,但域名不同,称为 若每个站点的IP地址相同 但域名不同, 地址相同, 基于名字或主机名的虚拟主机 • 若每个 若每个Web站点拥有不同的 地址,则称为基 站点拥有不同的IP地址 站点拥有不同的 地址, 于IP的虚拟主机 的虚拟主机 • • •Date: 18 October 2010Neusoft Institute of Information配置虚拟主机—基于主机名的虚拟主机的配置• 步骤: 步骤: –域名注册:使其能解析服务器所使用的IP地址。
域名注册: IP地址 域名注册 使其能解析服务器所使用的IP地址。
• /etc/hosts –创建多个web目录以及相对应的首页 创建多个web 创建多个web目录以及相对应的首页 –listen指令:在配制文件指定要监听的地址和端口。
listen指令 listen指令:在配制文件指定要监听的地址和端口。
–定义虚拟主机 : /etc/httpd/conf/httpd.conf 定义虚拟主机 • NameVirtualHost:使用哪个IP地址和端口接受请求。
Apache的工作原理Apache是一款常用的开源Web服务器软件,它能够接收来自客户端的HTTP请求并将相应的内容返回给客户端。
在这个任务中,我将详细介绍Apache的工作原理,包括工作流程、配置文件和模块等方面的内容。
一、工作流程1. 客户端发起HTTP请求:当客户端(例如浏览器)向服务器发送HTTP请求时,请求会通过网络传输到Apache服务器。
2. Apache接收请求:Apache服务器会接收到客户端发送的HTTP请求,并进行处理。
3. 解析请求:Apache会解析HTTP请求的内容,包括请求方法(GET、POST 等)、请求的URL和请求头等信息。
4. 处理请求:根据请求的URL,Apache会查找对应的资源文件或者处理程序。
如果请求的是静态文件(例如HTML、CSS、图片等),Apache会直接返回该文件;如果请求的是动态内容(例如PHP、ASP等),Apache会将请求转发给相应的处理程序进行处理。
5. 处理程序返回结果:处理程序会根据请求的内容进行相应的处理,并生成相应的响应结果。
6. 返回响应:Apache会将处理程序生成的响应结果返回给客户端。
7. 断开连接:一旦响应结果发送完毕,Apache会断开与客户端的连接,完成一次请求-响应过程。
二、配置文件Apache的配置文件是控征服务器行为的重要组成部份。
常见的Apache配置文件包括httpd.conf和apache2.conf。
1. httpd.conf:这是Apache服务器的主要配置文件。
它包含了全局配置指令、模块加载指令、虚拟主机配置等内容。
通过修改httpd.conf文件,可以对服务器的行为进行全局控制。
2. apache2.conf:这是Apache2版本的配置文件,与httpd.conf类似。
它通常包含一些全局配置指令和模块加载指令。
除了主要的配置文件外,Apache还可以通过.htaccess文件进行局部配置。
phpStudy的localhost不能访问怎么解决(相关性)phpStudy的localhost不能访问怎么解决(相关性)⼀、总结1、注释掉httpd.conf⽂件中的#ServerName localhost:80 这句话。
2、既然是localhost有问题,⽽别的域名没问题,那么在配置中去找和localhost有关的,对找出问题很有帮助。
(相关性)⼆、Apache配置虚拟主机后,不能访问localhost的问题1、问题描述今天想试⽤⼀下php7,但是发现php7只⽀持Apache2.4版本,⽽我电脑上的Apache是2.2版本,为了想尝鲜,就必须去下载新的Apache2.4 php7和apache2.4安装整合以后,localhost可以正常访问,没问题。
然后我⼜配置了⼏个虚拟主机,这时候,虚拟主机可以正常访问,但是localhost就访问不了了。
其实以前这种问题我也经历过,⽐如我之前⽤的php5.4搭配Apache2.2,就可以虚拟主机和localhost都可以访问;但是我之前怎么解决的我也不记得了,今天⼜折腾了好久,最后发现,其实就是注释掉⼀⾏代码的事情。
先说配置虚拟主机的流程:1.先打开httpd.conf⽂件,打开httpd-vhosts.conf# Virtual hostsInclude conf/extra/httpd-vhosts.conf2.然后打开httpd-vhosts.conf⽂件,配置⼀个虚拟主机<VirtualHost *:80>DocumentRoot "D:/amp/www/wechat"ServerName </VirtualHost>3.打开hosts⽂件,添加域名127.0.0.1 4.重启Apache,这时虚拟主机的域名可以正常访问, 但是我的localhost就不能访问了。
报错如下:2、解决过程:我的思路是,添加⼀个名为localhost的虚拟主机不就可以了?1.打开httpd-vhosts.conf⽂件,配置⼀个名为localhost的虚拟主机:<VirtualHost *:80>ServerName localhostDocumentRoot "D:/amp/www"</VirtualHost>2.打开hosts⽂件,添加域名注意:这⼀步,做或者不做,都没有影响,亲测通过。
一、实训背景随着互联网技术的飞速发展,服务器配置已成为IT行业的一项基础技能。
为了提高我们的实践能力,我们参加了本次服务器配置实训。
通过实训,我们对服务器配置有了更深入的了解,掌握了服务器的基本配置方法。
二、实训内容本次实训主要分为以下几个部分:1. Web服务器配置(1)安装Nginx和Apache服务器,并配置基本的网站。
(2)配置虚拟主机,实现多站点部署。
(3)配置SSL证书,实现HTTPS访问。
2. 客户端服务器配置(1)配置DNS服务器,实现域名解析。
(2)配置邮件服务器,实现邮件发送和接收。
3. 网络安全配置(1)配置防火墙,限制非法访问。
(2)配置SSH密钥,实现安全登录。
4. 其他配置(1)配置Samba服务,实现文件共享。
(2)配置NFS服务,实现跨主机文件共享。
三、实训过程及心得1. Web服务器配置在Web服务器配置过程中,我们首先学习了Nginx和Apache的基本原理和安装方法。
然后,我们通过配置虚拟主机,实现了多站点部署。
在配置过程中,我们遇到了一些问题,如虚拟主机配置错误、SSL证书安装失败等。
通过查阅资料和请教老师,我们逐步解决了这些问题。
2. 客户端服务器配置在客户端服务器配置过程中,我们学习了DNS服务器和邮件服务器的配置方法。
通过配置DNS服务器,我们实现了域名解析;通过配置邮件服务器,我们实现了邮件发送和接收。
在配置过程中,我们遇到了邮件服务器配置错误、DNS解析失败等问题,通过查阅资料和请教老师,我们逐步解决了这些问题。
3. 网络安全配置在网络安全配置过程中,我们学习了防火墙和SSH密钥的配置方法。
通过配置防火墙,我们限制了非法访问;通过配置SSH密钥,我们实现了安全登录。
在配置过程中,我们遇到了防火墙规则配置错误、SSH密钥生成失败等问题,通过查阅资料和请教老师,我们逐步解决了这些问题。
4. 其他配置在Samba和NFS服务配置过程中,我们学习了文件共享的配置方法。
Apache的工作原理Apache是一款开源的Web服务器软件,广泛应用于互联网和企业内部网络中。
它的工作原理涉及到请求处理、连接管理、模块化架构和配置文件等方面。
下面将详细介绍Apache的工作原理。
1. 请求处理当客户端发送HTTP请求到Apache服务器时,Apache会接收并解析请求。
它会根据请求的URL路径和其他相关信息来确定如何处理该请求。
Apache支持多种处理请求的方式,包括静态文件的传输、动态内容的生成和代理等。
2. 连接管理Apache使用多线程或者多进程的方式来管理连接。
当有新的请求到达时,Apache会分配一个线程或者进程来处理该请求。
这种方式可以同时处理多个请求,提高服务器的并发处理能力。
3. 模块化架构Apache的核心功能是通过模块来实现的。
模块是一段独立的代码,可以添加或者移除,以扩展或者修改Apache的功能。
Apache提供了丰富的模块,包括身份验证、URL重写、缓存等。
用户也可以开辟自己的模块来满足特定需求。
4. 配置文件Apache使用配置文件来定义服务器的行为。
配置文件包含了服务器的全局配置和虚拟主机配置。
全局配置包括监听端口、日志记录、模块加载等。
虚拟主机配置用于定义不同域名或者IP地址下的不同站点。
通过配置文件,可以灵便地调整服务器的行为。
5. 请求处理流程当Apache接收到一个请求时,它会按照一定的流程来处理该请求。
首先,Apache会根据请求的URL路径匹配到对应的虚拟主机配置。
然后,它会根据配置文件中的规则进行身份验证、URL重写等处理。
接下来,Apache会将请求交给适当的模块处理,例如静态文件模块或者动态内容模块。
最后,Apache会将处理结果返回给客户端。
6. 负载均衡Apache还支持负载均衡功能,可以将请求分发到多个后端服务器上,提高系统的可用性和性能。
负载均衡可以通过配置文件中的特定指令来实现,例如ProxyPass和ProxyPassReverse。
Apache的工作原理Apache是一款常用的开源Web服务器软件,广泛应用于互联网领域。
它的工作原理是通过接收来自客户端的HTTP请求,并将请求的资源返回给客户端。
1. 连接处理当客户端发起HTTP请求时,Apache会接收到该请求并建立与客户端的连接。
Apache使用TCP/IP协议进行通信,通过监听指定的端口来接收客户端请求。
2. 请求处理一旦建立连接,Apache会解析HTTP请求报文,提取出请求的方法、URL、协议版本等信息。
根据请求的URL,Apache会查找对应的虚拟主机配置,并将请求交给相应的虚拟主机进行处理。
3. 虚拟主机处理Apache支持虚拟主机技术,可以在一台服务器上托管多个域名或者网站。
每一个虚拟主机都有自己的配置文件,用于定义该主机的特定配置和处理规则。
当请求交给虚拟主机处理时,Apache会根据配置文件中的规则进行处理。
这些规则包括目录索引、重定向、访问控制、缓存等。
Apache还支持使用模块来扩展其功能,比如PHP模块用于解析PHP脚本。
4. 请求响应虚拟主机处理完请求后,会生成相应的HTTP响应报文,并将其返回给客户端。
响应报文包括状态码、响应头和响应体等部份。
状态码用于表示请求的处理结果,比如200表示请求成功,404表示资源未找到。
响应头包含了服务器的信息以及其他与响应相关的元数据。
响应体则是实际的响应内容,可以是HTML页面、图片、文件等。
5. 连接关闭一旦响应发送完成,Apache会关闭与客户端的连接。
在长连接的情况下,Apache会继续监听该连接上的其他请求。
除了以上的基本工作流程,Apache还具有一些高级特性和配置选项,如反向代理、负载均衡、SSL加密等。
这些功能可以根据实际需求进行配置和使用。
总结:Apache的工作原理可以简单概括为接收和处理客户端的HTTP请求,通过虚拟主机配置和规则进行请求处理,并生成相应的HTTP响应返回给客户端。
它是一个功能强大且可扩展的Web服务器软件,被广泛用于各种互联网应用场景。
mac 下apache+php+mysql(实践成功)一、启动apache 和设置虚拟访问路径。
mac系统默许已经安装了apachesudo apachectl start启动后,访问应该能看到"It works!"的初始页面,若是对初始页面的内容感到好奇,可以打开"/etc/apache2/",197行可以看到如下代码片段:It works的内容,网上说的之前的版本,是在/Library/WebServer/Documents/这个文件里,这是apache的默许页,我在Yosemite系统中没有发现这个文件,连webserver/documents文件夹都没找见,后来参考了一篇英文说明,才解决了无法访问的问题。
其它帖子都说的不够全面。
也不新。
解决虚拟主机无法访问的英文原文就不帖出来了,英文比较乱,我直接写操作步骤:默许情况下,apache的虚拟主机功能是关闭的,在“/etc/apache2/”中找到下面这行:#Include /private/etc/apache2/extra/将前面的#去掉,然后再打开“/etc/apache2/extra/”,内容修改成类似下面的样子:NameVirtualHost *:8023<VirtualHost *:80>4DocumentRoot "/Users/apple/Sites"5ServerName 6ErrorLog "/Users/apple/Sites/log/"7CustomLog "/Users/apple/Sites/log/" common8<Directory />9Options Indexes FollowSymLinks MultiViews10AllowOverride None11Order deny,allow12Allow from all13</Directory>14</VirtualHost>打开apache配置文件:sudo vim /etc/apache2/编辑apache配置文件:注释掉下面两行前面的##LoadModule userdir_module libexec/apache2/#Include /private/etc/apache2/extra/sudo vim /private/etc/apache2/extra/注释掉下面行前面的##Include /private/etc/apache2/users/*.conf最后你要成立/private/etc/apache2/users/ 若是文件不存在的话,内容依照以下的方式写上:<Directory "/Users/kevin/Sites/">Options Indexes MultiViewsAllowOverride NoneRequire all granted</Directory>sudo vim /private/etc/apache2/users/输入i 插入内容esc 后:wq 保留退出。
apach服务器配置大全(1)2011-09-16 23:02:00 来源:互联网一、资料参考与准备:Apache软件包的组成/etc/httpd/conf/*一、资料参考与准备:Apache软件包的组成/etc/httpd/conf/*主配置文件位置/etc/rc.d/init.d/httpd启动脚本/home/httpd/htmlhtml文档的主目录/home/httpd/html/manual/*html格式的帮助文档/home/httpd/icons/*用在html网页中的图标文件/usr/sbin/*-/usr/sbin/htpasswd建立和更新apache用户的程序-/usr/sbin/httpdhttp服务器程序/var/log/httpd/*日志文件主配置文件httpd.conf的常用指令解释ServerType standalone#设置服务器的形式是单独启动(standalone),还是借由互联网络伺服程序inetd来启动。
一般使用前者。
ServerRoot "/usr/local/apache"#设置服务器的Home目录,用来存放服务器的设置文件、错误文件、记录文件。
PidFile logs/httpd.pid#程序启动时,把父进程httpd的进程号(process id)存在这个文件中。
这个文件名可以配合PidFile 指令加以改变。
ScoreBoardFile logs/apache_status#设置网络上WWW服务器一些执行程序的记录文件。
#ResourceConfig conf/srm.conf#AccessConfig conf/access.conf#这两个文件的内容已经包含在httpd.conf文件中了。
Timeout 300#如果客户端300秒还没有连上,或者服务器300秒还没有传送数据到客户端,就会自动断线。
KeepAlive On#设置是否支持续传功能。
Apache的工作原理Apache是一种常用的开源Web服务器软件,它是基于HTTP协议的,用于响应客户端的HTTP请求并传送相应的Web页面或者其他资源。
Apache的工作原理主要包括请求处理、模块化架构和并发处理。
1. 请求处理:当客户端发送一个HTTP请求到Apache服务器时,Apache会按照一定的处理流程进行处理。
首先,Apache会解析请求的URL,获取请求的文件或者资源路径。
然后,Apache会根据配置文件中的规则,确定如何处理该请求,包括文件的位置、是否需要进行权限验证等。
2. 模块化架构:Apache采用模块化的架构,这意味着它的功能可以通过加载不同的模块来扩展。
Apache服务器的核心功能由一些基本模块提供,如核心模块、日志模块、认证模块等。
此外,还可以通过加载第三方模块来增加额外的功能,如PHP模块、SSL模块等。
模块化的架构使得Apache具有高度的灵便性和可扩展性,可以根据需求选择加载不同的模块。
3. 并发处理:Apache采用多进程或者多线程的方式来处理并发请求。
当有多个请求同时到达时,Apache会创建多个子进程或者线程来处理这些请求。
每一个子进程或者线程独立运行,互不干扰。
这样可以提高服务器的并发处理能力,同时也增加了服务器的稳定性和可靠性。
在Apache的工作过程中,还涉及到一些重要的概念和技术,如虚拟主机、URL重写、缓存等。
1. 虚拟主机:虚拟主机是指在一台物理服务器上运行多个独立的网站。
Apache可以通过配置虚拟主机来实现这一功能。
每一个虚拟主机有自己独立的域名或者IP地址,并且可以有自己独立的配置文件。
Apache根据请求的域名或者IP地址,将请求分发到相应的虚拟主机进行处理。
2. URL重写:URL重写是指将URL地址进行修改或者重定向的过程。
Apache可以通过配置URL重写规则来实现这一功能。
例如,可以将带有特定后缀的URL重写为另一个URL,或者将某个URL重定向到另一个URL。
Apache的配置⽂件,使⽤了⾃⼰的⽬录,添加了别名的使⽤(注意虚拟主机的优先级⽐⾮虚拟根⽬录的优先级要⾼,⽽且找不到其他虚拟主机的情况下会找配置⽬录下的第⼀台虚拟主机)This is the main Apache HTTP server configuration file. It contains theconfiguration directives that give the server its instructions. See for detailed information.In particular, seefor a discussion of each configuration directive.Do NOT simply read the instructions in here without understandingwhat they do. They're here only as hints or reminders. If you are unsureconsult the online docs. You have been warned. Configuration and logfile names: If the filenames you specify for manyof the server's control files begin with "/" (or "drive:/" forWin32), theserver will use that explicit path. If the filenames do not begin with "/", the value of ServerRoot is prepended -- so"logs/access_log"with ServerRoot set to "/usr/local/apache2" will be interpreted by theserver as "/usr/local/apache2/logs/access_log", whereas"/logs/access_log"will be interpreted as '/logs/access_log'.NOTE: Where filenames are specified, you must use forward slashesinstead of backslashes (e.g., "c:/apache" instead of"c:\apache").If a drive letter is omitted, the drive on which httpd.exe is locatedwill be used by default. It is recommended that you always supplyan explicit drive letter in absolute paths to avoid confusion. ServerRoot: The top of the directory tree under which the server'sconfiguration, error, and log files are kept.Do not add a slash at the end of the directory path. If you point ServerRoot at a non-local disk, be sure to specify a local disk on theMutex directive, if file-based mutexes are used. If you wish to share thesame ServerRoot for multiple httpd daemons, you will need to change atleast PidFile.ServerRoot "D:/xampp/apache"Mutex: Allows you to set the mutex mechanism and mutex file directoryfor individual mutexes, or change the global defaults Uncomment and change the directory if mutexes are file-based and the defaultmutex file directory is not on a local disk or is not appropriate for someother reason.Mutex default:logsListen: Allows you to bind Apache to specific IP addresses and/orports, instead of the default. See also thedirective.Change this to Listen on specific IP addresses as shown below toprevent Apache from glomming onto all bound IP addresses. Listen 12.34.56.78:80Listen 80Dynamic Shared Object (DSO) SupportTo be able to use the functionality of a module which was built as a DSO youhave to place corresponding `LoadModule' lines at this location so thedirectives contained in it are actually available before they are used.Statically compiled modules (those listed by `httpd -l') do not needto be loaded here.Example:LoadModule foo_module modules/mod_foo.soLoadModule access_compat_module modules/mod_access_compat.soLoadModule actions_module modules/mod_actions.soLoadModule alias_module modules/mod_alias.soLoadModule allowmethods_module modules/mod_allowmethods.soLoadModule asis_module modules/mod_asis.soLoadModule auth_basic_module modules/mod_auth_basic.soLoadModule auth_digest_modulemodules/mod_auth_digest.soLoadModule auth_form_module modules/mod_auth_form.so LoadModule authn_anon_modulemodules/mod_authn_anon.soLoadModule authn_core_module modules/mod_authn_core.soLoadModule authn_dbd_module modules/mod_authn_dbd.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_file_module modules/mod_authn_file.soLoadModule authn_socache_modulemodules/mod_authn_socache.soLoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so LoadModule authnz_ldap_modulemodules/mod_authnz_ldap.soLoadModule authz_core_module modules/mod_authz_core.soLoadModule authz_dbd_module modules/mod_authz_dbd.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.soLoadModule authz_host_module modules/mod_authz_host.soLoadModule authz_owner_modulemodules/mod_authz_owner.soLoadModule authz_user_module modules/mod_authz_user.soLoadModule autoindex_module modules/mod_autoindex.soLoadModule buffer_module modules/mod_buffer.so LoadModule cache_module modules/mod_cache.soLoadModule cache_disk_module modules/mod_cache_disk.so LoadModule cache_socache_modulemodules/mod_cache_socache.soLoadModule cern_meta_module modules/mod_cern_meta.so LoadModule cgi_module modules/mod_cgi.soLoadModule charset_lite_module modules/mod_charset_lite.so LoadModule data_module modules/mod_data.so LoadModule dav_module modules/mod_dav.so LoadModule dav_fs_module modules/mod_dav_fs.soLoadModule dav_lock_module modules/mod_dav_lock.soLoadModule dbd_module modules/mod_dbd.so LoadModule deflate_module modules/mod_deflate.soLoadModule dir_module modules/mod_dir.soLoadModule dumpio_module modules/mod_dumpio.soLoadModule env_module modules/mod_env.soLoadModule expires_module modules/mod_expires.so LoadModule ext_filter_module modules/mod_ext_filter.so LoadModule file_cache_module modules/mod_file_cache.so LoadModule filter_module modules/mod_filter.so LoadModule http2_module modules/mod_http2.soLoadModule headers_module modules/mod_headers.soLoadModule heartbeat_module modules/mod_heartbeat.so LoadModule heartmonitor_modulemodules/mod_heartmonitor.soLoadModule ident_module modules/mod_ident.soLoadModule imagemap_module modules/mod_imagemap.so LoadModule include_module modules/mod_include.soLoadModule info_module modules/mod_info.soLoadModule isapi_module modules/mod_isapi.soLoadModule lbmethod_bybusyness_modulemodules/mod_lbmethod_bybusyness.soLoadModule lbmethod_byrequests_modulemodules/mod_lbmethod_byrequests.soLoadModule lbmethod_bytraffic_modulemodules/mod_lbmethod_bytraffic.soLoadModule lbmethod_heartbeat_modulemodules/mod_lbmethod_heartbeat.soLoadModule ldap_module modules/mod_ldap.so LoadModule logio_module modules/mod_logio.soLoadModule log_config_module modules/mod_log_config.soLoadModule log_debug_module modules/mod_log_debug.so LoadModule log_forensic_modulemodules/mod_log_forensic.soLoadModule lua_module modules/mod_lua.soLoadModule cache_disk_module modules/mod_cache_disk.soLoadModule macro_module modules/mod_macro.soLoadModule mime_module modules/mod_mime.soLoadModule mime_magic_modulemodules/mod_mime_magic.soLoadModule negotiation_module modules/mod_negotiation.soLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_ajp_module modules/mod_proxy_ajp.soLoadModule proxy_balancer_modulemodules/mod_proxy_balancer.soLoadModule proxy_connect_modulemodules/mod_proxy_connect.soLoadModule proxy_express_modulemodules/mod_proxy_express.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_html_module modules/mod_proxy_html.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_scgi_module modules/mod_proxy_scgi.so LoadModule proxy_wstunnel_modulemodules/mod_proxy_wstunnel.soLoadModule ratelimit_module modules/mod_ratelimit.so LoadModule reflector_module modules/mod_reflector.so LoadModule remoteip_module modules/mod_remoteip.so LoadModule request_module modules/mod_request.so LoadModule reqtimeout_module modules/mod_reqtimeout.so LoadModule rewrite_module modules/mod_rewrite.soLoadModule sed_module modules/mod_sed.so LoadModule session_module modules/mod_session.so LoadModule session_cookie_modulemodules/mod_session_cookie.soLoadModule session_crypto_modulemodules/mod_session_crypto.soLoadModule session_dbd_modulemodules/mod_session_dbd.soLoadModule setenvif_module modules/mod_setenvif.soLoadModule slotmem_plain_modulemodules/mod_slotmem_plain.soLoadModule slotmem_shm_modulemodules/mod_slotmem_shm.soLoadModule socache_dbm_modulemodules/mod_socache_dbm.soLoadModule socache_memcache_modulemodules/mod_socache_memcache.soLoadModule socache_shmcb_module modules/mod_socache_shmcb.soLoadModule speling_module modules/mod_speling.soLoadModule ssl_module modules/mod_ssl.soLoadModule status_module modules/mod_status.soLoadModule substitute_module modules/mod_substitute.so LoadModule unique_id_module modules/mod_unique_id.so LoadModule userdir_module modules/mod_userdir.so LoadModule usertrack_module modules/mod_usertrack.so LoadModule version_module modules/mod_version.soLoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule watchdog_module modules/mod_watchdog.so LoadModule xml2enc_module modules/mod_xml2enc.so# # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User daemon Group daemon'Main' server configurationThe directives in this section set up the values used by the'main'server, which responds to any requests that aren't handled byadefinition. These values also provide defaults forany 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 bee-mailed. This address appears on some server-generated pages, suchas error documents. e.g. admin@ServerAdmin postmaster@localhostServerName gives the name and port that the server uses to identify itself.This can often be determined automatically, but we recommend you specifyit explicitly to prevent problems during startup.If your host doesn't have a registered DNS name, enter its IP address here.ServerName localhost:80Deny access to the entirety of your server's filesystem. You mustexplicitly permit access to web content directories in other blocks below.AllowOverride none #Require all denied Options Indexes FollowSymLinks Order deny,allow Allow from allNote that from this point forward you must specifically allowparticular features to be enabled - so if something's not working asyou might expect, make sure that you have specifically enabled itbelow.DocumentRoot: The directory out of which you will serve your documents. By default, all requests are taken from this directory, butsymbolic links and aliases may be used to point to other locations.DocumentRoot "E:/webroot/www"<Directory "E:/webroot/www">DocumentRoot "D:/xampp/htdocs"<Directory "D:/xampp/htdocs">## 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't give it to you.## The Options directive is both complicated and important. Please see# /docs/2.4/mod/core.html#options# for more information.#Options Indexes FollowSymLinks Includes ExecCGI## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# AllowOverride FileInfo AuthConfig Limit#AllowOverride All## Controls who can get stuff from this server.#Require all grantedDirectoryIndex: sets the file that Apache will serve if a directory is requested.DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \ default.php default.pl default.cgi default.asp default.shtml default.html default.htm \ home.php home.pl home.cgi home.asp home.shtml home.html home.htmThe following lines prevent .htaccess and .htpasswd files frombeingviewed by Web clients.<Files ".ht*">Require all deniedErrorLog: The location of the error log file.If you do not specify an ErrorLog directive within a container, error messages relating to that virtual host will be logged here. If you do define an error logfile for a container, that host's errors will be logged there and not here. ErrorLog "logs/error.log"LogLevel: Control the number of messages logged to the error_log.Possible values include: debug, info, notice, warn, error, crit, alert, emerg.LogLevel warn# # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module># You need to enable mod_logio.c to use %I and %OLogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio</IfModule>## The location and format of the access logfile (Common Logfile Format).# If you do not define any access logfiles within a <VirtualHost># container, they will be logged here. Contrariwise, if you *do*# define per-<VirtualHost> access logfiles, transactions will be# logged therein and *not* in this file.##CustomLog "logs/access.log" common## If you prefer a logfile with access, agent, and referer information# (Combined Logfile Format) you can use the following directive.#CustomLog "logs/access.log" combined# # Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo /bar## Alias: Maps web paths into filesystem paths and is used to# access content that does not live under the DocumentRoot.# Example:# Alias /webpath /full/filesystem/path## If you include a trailing / on /webpath then the server will# require it to be present in the URL. You will also likely# need to provide a <Directory> section to allow access to# the filesystem path.## ScriptAlias: This controls which directories contain server scripts.# ScriptAliases are essentially the same as Aliases, except that# documents in the target directory are treated as applications and# run by the server when requested rather than as documents sent to the# client. The same rules about trailing "/" apply to ScriptAlias# directives as to Alias.#ScriptAlias /cgi-bin/ "D:/xampp/cgi-bin/"# # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock cgisock"D:/xampp/cgi-bin" should be changed to whatever your ScriptAliasedCGI directory exists, if you have that configured.<Directory "D:/xampp/cgi-bin">AllowOverride AllOptions NoneRequire all granted# # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig conf/mime.types ## AddType allows you to add to or override the MIME configuration# file specified in TypesConfig for specific file types.##AddType application/x-gzip .tgz## AddEncoding allows you to have certain browsers uncompress# information on the fly. Note: Not all browsers support this.##AddEncoding x-compress .Z#AddEncoding x-gzip .gz .tgz## If the AddEncoding directives above are commented-out, then you# probably should define those extensions to indicate media types:#AddType application/x-compress .ZAddType application/x-gzip .gz .tgz## AddHandler allows you to map certain file extensions to "handlers":# actions unrelated to filetype. These can be either built into the server# or added with the Action directive (see below)## To use CGI scripts outside of ScriptAliased directories:# (You will also need to add "ExecCGI" to the "Options" directive.)#AddHandler cgi-script .cgi .pl .asp# For type maps (negotiated resources):#AddHandler type-map var## Filters allow you to process content before it is sent to the client.## To parse .shtml files for server-side includes (SSI):# (You will also need to add "Includes" to the "Options" directive.)#AddType text/html .shtmlAddOutputFilter INCLUDES .shtmlThe mod_mime_magic module allows the server to use various hints from thecontents of the file itself to determine its type. The MIMEMagicFiledirective tells the module where the hint definitions are located.# # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # MIMEMagicFile "conf/magic" Customizable error responses come in three flavors:1) plain text 2) local redirects 3) external redirectsSome examples:ErrorDocument 500 "The server made a boo boo." ErrorDocument 404 /missing.htmlErrorDocument 404 "/cgi-bin/missing_handler.pl" ErrorDocument 402MaxRanges: Maximum number of Ranges in a request before returning the entire resource, or one of the specialvalues 'default', 'none' or 'unlimited'.Default setting is to accept 200 Ranges.MaxRanges unlimitedEnableMMAP and EnableSendfile: On systems that support it, memory-mapping or the sendfile syscall may be used to deliver files. This usually improves server performance, but mustbe turned off when serving from networked-mounted filesystems or if support for these functions is otherwise broken on your system.Defaults: EnableMMAP On, EnableSendfile Off EnableMMAP offEnableSendfile offSupplemental configurationThe configuration files in the conf/extra/ directory can be included to add extra features or to modify the default configuration ofthe server, or you may simply copy their contents here and change asnecessary.Server-pool management (MPM specific)Include conf/extra/httpd-mpm.confMulti-language error messagesInclude conf/extra/httpd-multilang-errordoc.confFancy directory listingsInclude conf/extra/httpd-autoindex.confLanguage settingsInclude conf/extra/httpd-languages.confUser home directoriesInclude conf/extra/httpd-userdir.confReal-time info on requests and configurationInclude conf/extra/httpd-info.confVirtual hostsInclude conf/extra/httpd-vhosts.confLocal access to the Apache HTTP Server ManualInclude conf/extra/httpd-manual.confDistributed authoring and versioning (WebDAV) Attention! WEB_DAV is a security risk without a newuserspecific configuration for a secure authentifcation Include conf/extra/httpd-dav.confVarious default settingsInclude conf/extra/httpd-default.confImplements a proxy/gateway for Apache.Include "conf/extra/httpd-proxy.conf"Various default settingsInclude "conf/extra/httpd-default.conf"XAMPP settingsInclude "conf/extra/httpd-xampp.conf"Configure mod_proxy_html to understand HTML4/XHTML1Include conf/extra/proxy-html.confSecure (SSL/TLS) connectionsInclude conf/extra/httpd-ssl.confNote: The following must must be present to supportstarting without SSL on platforms with no /dev/random equivalentbut a statically compiled-in mod_ssl.SSLRandomSeed startup builtin SSLRandomSeed connect builtin # # uncomment out the below to deal with user agents that deliberately # violate open standards by misusing DNT (DNT *must* be a specific # end-user choice) # # #BrowserMatch "MSIE 10.0;" bad_DNT # # #RequestHeader unset DNT env=bad_DNT #XAMPP: We disable operating system specific optimizations for a listeningsocket by the http protocol here. IE 64 bit make problems without this.AcceptFilter http noneAcceptFilter https noneAJP13 ProxyInclude "conf/extra/httpd-ajp.conf"别名设置Alias /images/ "E:/webroot/images/" <Directory "E:/webroot/images/"> Options Indexes FollowSymLinks AllowOverride NoneOrder deny,allowAllow from all。
配置apache虚拟主机 通过以下文章:实现:同一ip不同端口对应不同的站点目录 具体实现: 1.在httpd.conf中,设置listen IP:80 listen IP:8080 然后在virtualhost中设置: DocumnetRoot 1 DocumnetRoot 2 我们通常所说的虚拟主机 [url=javascript:;]技术[/url] 就是将一台(或者一组)服务器的资源(系统资源、网络带宽、存储空间等)按照一定的比例分割成若干台相对独立的“小主机”的技术。每一台这样的“小主机”在功能上都可以实现 WWW、FTP、Mail等基本的Internet服务,就像使用独立的主机一样。
目前网站服务器的虚拟主机平台使用以开放的Apache为最多,其次是微软的Windows IIS。Apache具有跨平台(FreeBSD/Linux/Windows/Solaris/Other UNIX)、易于维护与最佳安全性等优点。 Apache是率先支持基于IP虚拟主机的服务器之一。 Apache 1.1及其更新版本同时支持基于IP和基于主机名的虚拟主机,不同的虚拟主机有时会被称为基于主机(host-based) 或非IP虚拟主机(non-IP virtual hosts)。 用Apache设置虚拟主机服务通常可以采用两种方案:基于IP地址的虚拟主机和基于主机名字的虚拟主机,下面我们分别介绍一下它们的实现方法以及优缺点。以便大家在具体的应用中能够选择最合适的实现方法。
一、Apache实现基于IP地址的虚拟主机(每个站点拥有一个独立IP地址) 使用这种虚拟主机方式,首先要在服务器上为每个虚拟主机单独设置一个IP地址。这些IP地址可以通过增加多个网卡或者在一个网卡上设立多个IP地址来完成。有了多个IP地址后,可以采用以下两种方式之一来设置Apache。 1、为每个虚拟主机运行一份Apache 采用这种方式,每一份Apache程序可以以单独的用户运行,因此各个虚拟主机之间互不影响。设置这种虚拟主机时,只要为每一份Apache设置一套配置文件就可以了,唯一需要注意的是:必须使用“Listen”语句,强制每一份Apache 仅仅在属于“自己”的IP地址上接收服务请求。 优点:各个虚拟主机之间互不干扰,安全性高。 缺点:占用系统资源较多。 2、多个虚拟主机共享同一份Apache 采用这种方式,各个虚拟主机共享同一份Apache,因此各个虚拟主机之间有一定的影响,尤其是执行CGI程序时,可能会带来一些严重的安全问题。设置这种虚拟主机时,只要为每一个虚拟主机设置类似如下的信息即可:
DocumentRoot /www/ghq1 … 优点:占用系统资源比上一种方式少。 缺点:安全性低,每个虚拟主机仍然需要占用一个IP地址。
例如服务器一个网卡上绑定有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org的服务,配置如下: 服务器配置(apache的配置文件httpd.conf) Listen 80
DocumentRoot /www/ghq1 ServerName www.ghq1.com
DocumentRoot /www/ghq2 ServerName www.ghq2.org
配置简单说明:“Listen”默认httpd服务会监控第80号通信端口, “Listen”选项让用户自行指定apache 服务器监控的IP地址或通信端口。 “DocumentRoot”:指定apache 服务器存放网页的根目录;“ServerName”:允许用户自行设置主机名,这个名称将被送到远程连接程序,以取代安装apache 服务器主机的真实名称。和构成虚拟主机的语法结构,其中的IP就是我们在服务器上绑定的不同的IP地址,也可以是IP地址加上通信端口号(见下面的例子)。 如果服务器有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org。对每个域名,我们都希望在80端口和8080端口发布我们的网站。可以这样配置: 服务器配置(apache的配置文件httpd.conf) Listen 172.16.3.40:80 Listen 172.16.3.40:8080 Listen 172.16.3.50:80 Listen 172.16.3.50:8080
DocumentRoot /www/ghq1-80 ServerName www.ghq1.com
DocumentRoot /www/ghq1-8080 ServerName www.ghq1.com
DocumentRoot /www/ghq2-80 ServerName www.ghq1.org
DocumentRoot /www/ghq2-8080 ServerName www.ghq2.org 因此,建立虚拟主机,我们要做好不同的IP对应的域名解析 [url=javascript:;]工作[/url] ,建立相应的目录(如/www/ghq1),将相应的主页内容存放在相应的目录中即可。 二、Apache实现基于主机名的虚拟主机服务(一个IP地址实现多个网站)
基于主机名字的虚拟主机服务,是目前虚拟主机比较常用的一种方案。因为它不需要更多的IP地址,无须什么特殊的软硬件支持。而且现在的浏览器大都支持这种虚拟主机的实现方法。基于域名的的虚拟主机是根据客户端提交的HTTP头中的关于主机名的部分决定的。使用这种技术,很多虚拟主机可以享用同一个IP地址。 基于域名的虚拟主机相对比较简单,因为我们只需要配置DNS服务器将每个主机名映射(CNAMES)到正确的IP地址,然后配置Apache HTTP服务器,令其辨识不同的主机名就可以了。基于域名的服务器也可以缓解IP地址(IPV4)不足的问题。这种方式下,各个虚拟主机共享同一份Apache,因此有CGI程序运行时,安全性也不高。 优点:只要一个IP地址就可以提供大量的虚拟主机服务。 缺点:安全性差。维护这些虚拟主机时需要更改配置文件,并且需要重新启动Apache进程才能起作用。因此不适合进行大规模的虚拟主机服务。 如果服务器只有一个IP地址,而在DNS中有很多映射到这个机器。我们想要在这个机器上运行www.ghq1.com和 www.ghq2.org两个站点。在Apache服务器的配置中创建一个虚拟主机并不会自动在DNS中对主机名做相应更新。我们必须自己在DNS中添加域名来指向我们的IP地址。否则别人是无法看到我们的web 站点。 服务器配置(apache的配置文件httpd.conf) # Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *
DocumentRoot /www/ghq1 ServerName www.ghq1.com # Other directives here
DocumentRoot /www/ghq2 ServerName www.ghq2.org # Other directives here
因为*(星号)匹配所有的地址,所以主服务器不接收任何请求。因为 www.ghq1.com首先出现在配置文件中,所以它拥有最高优先级,可以认为是默认或首要服务器。这意味着如果一个接受的请求不能与某个ServerName指令相匹配, 它将会由第一个VirtualHost所伺服。 当我们的IP地址无法确定的时候,使用*是很方便的--比如说, ISP给我们配置的是动态IP地址(如ADSL拨号上网),而我们有使用了某种动态域名解析系统时。因为*匹配任何IP 地址,所以在这样的情况下,不论IP地址如何变化,我们都不需要另外进行配置。上述配置就是我们在绝大多数情况下使用基于域名的虚拟主机时将要用到的。 关于DNS和Apache 本文档的涵义一言以蔽之就是:不要让Apache在解析配置文件的时候用到DNS。 如果Apache在解析配置文件时用到了DNS,您的服务器就会发生可靠性的问题(也可能根本无法启动), 或者遭致拒绝(偷窃)服务攻击(包括用户可以从其他用户那里偷窃点击)。 一个简单示例 拒绝服务 "main server"地址 避免这些问题的小技巧 附录:进一步的提示 一个简单示例
ServerAdmin webgirl@abc.dom DocumentRoot /www/abc
为了让Apache功能正常,一个虚拟主机绝对需要以下两部分的信息: ServerName和与服务器对应的至少一个IP地址。 这个示例没有包括IP地址,于是Apache必须用DNS来查询www.abc.dom的地址。 如果在某些不可预料的情况下,当您的服务器解析配置文件时没有得到DNS的支持, 那么这个虚拟主机 将不会被配置。 它将不会对任何请求作出反应。(在Apache的1.2版本之前,服务器甚至无法启动)。 假设www.abc.dom的IP地址是10.0.0.1。那么看看以下这个配置片断:
ServerAdmin webgirl@abc.dom DocumentRoot /www/abc
现在Apache需要DNS对这个虚拟主机进行反向域名解析来确定ServerName。 如果反向解析失败,那么这将导致这个虚拟主机部分功能丧失。 (在Apache的1.2版本之前,服务器将不能启动)。如果虚拟主机是基于域名的, 它将完全不能使用,但如果它是基于IP的,那么它将很有可能工作。 然而,如果Apache不得不为一个已经包含了服务器域名的服务器产生一个完整的URL, 那么它将可能产生一个无效的URL。 以下是一个可以避免上述两个问题的配置片断.
ServerName www.abc.dom ServerAdmin webgirl@abc.dom DocumentRoot /www/abc
拒绝服务 拒绝服务主要由(至少)两种形式导致。 如果您在运行Apache 1.2以前的版本,在上述两种情况下,如果您的任何一个虚拟主机的DNS解析失败,您都会无法启动服务。在一些情况下,DNS解析甚至不在您的控制范围之内。 比如说,如果abc.dom是您的一个客户,而且他们自己控制着DNS。 那么仅仅是因为他们删除了www.abc.dom这个记录, 都会导致您的服务器(1.2之前的版本)无法启动。 另外一种形式就更隐蔽了。比如说下面这个配置片断: