ASF:Apache Software Foundation www.apache.org
开源项目
web:httpd http://httpd.apache.org
tomcat:应用程序服务器
hadoop:并行处理
httpd版本:
2.0稳定版本
2.2流行版本
2.4最新版本
httpd特性:
事先创建进程
按需维持适当的进程
模块化设计,核心比较小,各种功能都通过模块添加(包括php)
支持运行时配置,支持单独编译模块
支持多种方式的虚拟主机配置
虚拟主机:
基于IP的虚拟主机:
基于端口的虚拟主机:
基于域名的虚拟主机:根据请求报文headers字段的host:HOST_NAME
支持https协议 (mod_ssl)
支持用户认证
支持基于IP或主机名的ACL
支持每目录的访问控制
支持URL重写
RedHat安装httpd:(事先让SELinux处于permssive, disabled)
rpm包:
源码编译:自定义性更强,自行选择编译需要的特性或模块
httpd的相关文件:
/usr/sbin/httpd(多道处理模式MPM:prefork) 事先创建进程
开启httpd服务后,创建多个httpd进程
一个httpd:root,root (master process)
多个httpd:apache,apache (worker process)
/etc/rc.d/init.d/httpd
port:(80/tcp),(ssl:443/tcp)
/etc/httpd:工作根目录,相当于程序安装目录
/etc/httpd/conf:配置文件目录
主配置文件:httpd.conf
/etc/httpd/conf.d/*.conf 主配置文件的组成配置
/etc/httpd/modules:模块目录
/etc/httpd/logs --> /var/log/httpd:日志目录
日志文件有两类:访问日志access_log,错误日志:err_log
/var/www/
html/
cgi-bin/:动态内容
cgi (Common Gateway Interface):让web服务器能根据请求的内容去启动额外的程序处理请求内容
perl,python,java,(Servlet,JSP),php开发
fastcgi:
程序:指令和数据
管理数据,数据库服务
MPM:Muti Path Modules多道处理模块
mpm_winnt
prefork(一个请求用一个进程响应) 稳定可靠,性能差
worker(一个请求用一个线程响应,(启动多个进程,每个进程生成多个线程)) 要解决进程同时写时的 锁问题
event(一个进程处理多个请求)
切换:
修改/etc/sysconfig/httpd下的变量HTTP
配置文件/etc/httpd/conf/httpd.conf
[email protected] ~]# grep ‘\<Section\>‘ /etc/httpd/conf/httpd.conf -n 33:### Section 1: Global Environment 234:### Section 2: ‘Main‘ server configuration 961:### Section 3: Virtual Hosts
Section 1:Global Environment
### Section 1: Global Environment ServerTokens OS #出现错误页时是否显示服务器操作系统的名称 ServerTokens Prod为不显示 # ServerRoot "/etc/httpd" #指定Apache的运行目录 # PidFile run/httpd.pid #指定的文件将记录httpd父进程(root:root)的进程号 # Timeout 120 #定义超时时间,超过就断开链接 # KeepAlive Off #是否开启长连接 # MaxKeepAliveRequests 100 #一次长连接可以进行的http请求的最大请求次数 # KeepAliveTimeout 15 #一次长链接的最长连接时间,超过就断开 ## ## Server-Pool Size Regulation (MPM specific) ## # prefork MPM <IfModule prefork.c> StartServers 8 #开始进程数 MinSpareServers 5 #最小空闲进程数 MaxSpareServers 20 #最大空闲进程数 ServerLimit 256 #进程限制数 MaxClients 256 #同时间最大的客户端连接数 MaxRequestsPerChild 4000 #每个进程最大的处理请求数,超过就要kill掉 </IfModule> # worker MPM <IfModule worker.c> StartServers 2 #开始进程数 MaxClients 150 #同时间最大的客户端连接数 MinSpareThreads 25 #最小空闲线程数 MaxSpareThreads 75 #最大空闲线程数 ThreadsPerChild 25 #每个线程最大的处理请求数,超过就要kill掉 MaxRequestsPerChild 0 #每个进程最大的处理请求数,超过就要kill掉 #0表示无限制 </IfModule> # Listen 80 #Server监听的端口号,可指定特定网卡 Listen IP:80 # # Dynamic Shared Object (DSO) Support #加载的模块 LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_default_module modules/mod_authn_default.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_default_module modules/mod_authz_default.so LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so LoadModule include_module modules/mod_include.so LoadModule log_config_module modules/mod_log_config.so LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so LoadModule ext_filter_module modules/mod_ext_filter.so LoadModule mime_magic_module modules/mod_mime_magic.so LoadModule expires_module modules/mod_expires.so LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so LoadModule usertrack_module modules/mod_usertrack.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule mime_module modules/mod_mime.so LoadModule dav_module modules/mod_dav.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule info_module modules/mod_info.so LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so LoadModule actions_module modules/mod_actions.so LoadModule speling_module modules/mod_speling.so LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule cache_module modules/mod_cache.so LoadModule suexec_module modules/mod_suexec.so LoadModule disk_cache_module modules/mod_disk_cache.so LoadModule file_cache_module modules/mod_file_cache.so LoadModule mem_cache_module modules/mod_mem_cache.so LoadModule cgi_module modules/mod_cgi.so LoadModule version_module modules/mod_version.so # # The following modules are not loaded by default: # #LoadModule cern_meta_module modules/mod_cern_meta.so #LoadModule asis_module modules/mod_asis.so # Include conf.d/*.conf #加载的配置文件 # #ExtendedStatus On #让Server可以报告更详细的运行状态信息 # User apache #httpd启动后的属主 Group apache #httpd启动后的属组
Section 2: ‘Main‘ server configuration
### Section 2: ‘Main‘ server configuration # ServerAdmin [email protected] #管理员的邮箱 # #ServerName #提供主机名,默认server会反向解析得到自己的ServerName # # UseCanonicalName: Determines how Apache constructs self-referencing # URLs and the SERVER_NAME and SERVER_PORT variables. # When set "Off", Apache will use the Hostname and Port supplied # by the client. When set "On", Apache will use the value of the # ServerName directive. # UseCanonicalName Off #如果上面定义了ServerName,set "On"就会使用上面的值构建自引用URL # DocumentRoot "/var/www/html" #网页文件存放的目录 # #对根目录的权限设置 <Directory /> Options FollowSymLinks AllowOverride None </Directory> # #对/var/www/html目录的权限设置 <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # #Indexes表示当网页不存在时允许索引显示目录中的文件 #FollowSymLinks表示允许访问符号链接文件 #ExecCGI表示使用CGI # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # #AllowOverride的参数: #AuthConfig 允许使用与认证授权相关的指令(AuthDBMGroupFile, AuthDBMUserFile, AuthGroupF#ile, AuthName, AuthType, AuthUserFile, Require,等)。 #FileInfo #允许使用控制文档类型的指令(DefaultType, ErrorDocument, ForceType, LanguagePriority, #SetHandler, SetInputFilter, SetOutputFilter, mod_mime中的 Add*和Remove*指令等等)、控#制文档元数据的指令(Header, RequestHeader, SetEnvIf, SetEnvIfNoCase, BrowserMatch, C#ookieExpires, CookieDomain, CookieStyle, CookieTracking,CookieName)、mod_rewrite中的 #指令(RewriteEngine, RewriteOptions, RewriteBase, RewriteCond, RewriteRule)和mod_acti#ons中的Action指令。 #Indexes #允许使用控制目录索引的指令(AddDescription, AddIcon, AddIconByEncoding, AddIconByType,# DefaultIcon, DirectoryIndex, FancyIndexing, HeaderName, IndexIgnore, IndexOptions#, ReadmeName, 等)。 #Limit #允许使用控制主机访问的指令(Allow, Deny, Order)。 # Options FileInfo AuthConfig Limit # AllowOverride AuthConfig AuthType Basic AuthName "Restricted Site..." AuthUserFile "/etc/httpd/conf/htpasswd" #用户认证文件,htpasswd -c(首次创建文件要用- #c选项) -m /path/to/passwdfile USERNAME AuthGroupFile "/etc/httpd/conf/htpgroup" #用户组认证文件,手动创建,文件格式 #GROUPNAME: USERNAME1 USERNAME2 ... # Require valid-user #所有用户认证 # Require user hadoop #指定用户认证 Require group mygroup #用户组认证 # # Controls who can get stuff from this server. # Order allow,deny #先允许以下指定允许的,再拒绝所有 Allow from all </Directory> # UserDir: The name of the directory that is appended onto a user‘s home # directory if a ~user request is received. <IfModule mod_userdir.c> # # UserDir is disabled by default since it can confirm the presence # of a username on the system (depending on home directory # permissions). # UserDir disable # # To enable requests to /~user/ to serve the user‘s public_html # directory, remove the "UserDir disable" line above, and uncomment # the following line instead: # #UserDir public_html </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # #<Directory /home/*/public_html> # AllowOverride FileInfo AuthConfig Limit # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec # <Limit GET POST OPTIONS> #限定语句,对GET POST OPTIONS请求进行限定 # Order allow,deny # # Allow from all #允许所有 # </Limit> # <LimitExcept GET POST OPTIONS> #限定语句,对GET POST OPTIONS以外的请求进 #行限定 # Order deny,allow # # Deny from all #拒绝所有 # </LimitExcept> #</Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # DirectoryIndex index.html index.html.var #预设的HTML目录索引文件名 # # AccessFileName: The name of the file to look for in each directory # for additional configuration directives. See also the AllowOverride # directive. # AccessFileName .htaccess #每个目录中用于控制访问信息的文件名 # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ~ "^\.ht"> #文件限制语句 Order allow,deny Deny from all </Files> # # TypesConfig describes where the mime.types file (or equivalent) is # to be found. # TypesConfig /etc/mime.types #用于设置保存有不同MIME类型数据的文件名 # DefaultType text/plain #定义文档的缺省类型,不能判断出文档的MIME时,使用text/plain #格式发送回去 # #除了从文件的后缀出发来判断文件的MIME类型之外,Apache还可以进一步分析文件的一些特征,来判#断文件的真实MIME类型。这个功能是由mod_mime_magic模块实现的,它需要一个记录各种MIME类型特#征的文件,以进行分析判断。上面的设置是一个条件语句,如果载入了这个模块,就必须指定相应的#标志文件magic的位置。 # <IfModule mod_mime_magic.c> # MIMEMagicFile /usr/share/magic.mime #指示模块文件标识的定义所在的位置 MIMEMagicFile conf/magic </IfModule> # #通常连接时,服务器仅仅可以得到客户机的IP地址,如果要想获得客户机的主机名,以进行日志记录#和提供给 CGI程序使用,就需要使用这个HostnameLookups选项,将其设置为On打开DNS反查功能。但#是这将使服务器对每次客户请求都进行DNS查询,增加了系统开销,使得反应变慢,因此缺省设置为 #使用Off关闭此选项。关闭选项之后,服务器就不会获得客户机的主机名,而只能使用IP地址来记录 #客户。 # HostnameLookups Off # # EnableMMAP: Control whether memory-mapping is used to deliver # files (assuming that the underlying OS supports it). # The default is on; turn this off if you serve from NFS-mounted # filesystems. On some systems, turning it off (regardless of # filesystem) can improve performance; for details, please see # http://httpd.apache.org/docs/2.2/mod/core.html#enablemmap # #EnableMMAP off # # EnableSendfile: Control whether the sendfile kernel support is # used to deliver files (assuming that the OS supports it). # The default is on; turn this off if you serve from NFS-mounted # filesystems. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile # #EnableSendfile off # 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 LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent # "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this # requires the mod_logio module to be loaded. #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedi#o # CustomLog logs/access_log combined # #一些情况下,例如当客户请求的网页并不存在时,服务器将产生错误文档,缺省情况下由于打开了 S#erverSignature选项,错误文档的最后一行将包含服务器的名字、Apache的版本等信息。有的管理员#更倾向于不对外显示这些信息,就可以将这个参数设置为Off,或者设置为Email,最后一行将替换为#对ServerAdmin 的Email提示。 # ServerSignature On Alias /icons/ "/var/www/icons/" #/icons/的别名为/var/www/icons/ <Directory "/var/www/icons"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> # # WebDAV module configuration section. # <IfModule mod_dav_fs.c> # Location of the WebDAV lock database. DAVLockDB /var/lib/dav/lockdb </IfModule> # # scriptAlias: 控制哪个目录包含服务器脚本。 # scriptAlias本质行和Aliases一样。, except that # 区别在于真名目录中的文档被看作是一个应用程序。 # 请求时由服务器运行而不是发往客户端。 # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> # #Redirect参数是用来重写URL的,当浏览器访问服务器上的一个已经不存在的资源的时候,服务器返 #回给浏览器新的URL,告诉浏览器从该URL中获取资源。这主要用于原来存在于服务器上的文档,改变#了位置之后,而又希望能使用老URL能访问到,以保持与以前的URL兼容。 # 格式: Redirect old-URL new-URL # Example: # Redirect permanent /foo http://www.example.com/bar # # IndexOptions: Controls the appearance of server-generated directory # listings. # IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable # # AddIcon*表明不同文件或扩展名在Index中显示的图标 # AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip AddIconByType (TXT,/icons/text.gif) text/* AddIconByType (IMG,/icons/image2.gif) image/* AddIconByType (SND,/icons/sound2.gif) audio/* AddIconByType (VID,/icons/movie.gif) video/* AddIcon /icons/binary.gif .bin .exe AddIcon /icons/binhex.gif .hqx AddIcon /icons/tar.gif .tar AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip AddIcon /icons/a.gif .ps .ai .eps AddIcon /icons/layout.gif .html .shtml .htm .pdf AddIcon /icons/text.gif .txt AddIcon /icons/c.gif .c AddIcon /icons/p.gif .pl .py AddIcon /icons/f.gif .for AddIcon /icons/dvi.gif .dvi AddIcon /icons/uuencoded.gif .uu AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl AddIcon /icons/tex.gif .tex AddIcon /icons/bomb.gif core AddIcon /icons/back.gif .. AddIcon /icons/hand.right.gif README AddIcon /icons/folder.gif ^^DIRECTORY^^ AddIcon /icons/blank.gif ^^BLANKICON^^ # #DefaultIcon用于为指定图标的文件所显示的图标 # DefaultIcon /icons/unknown.gif # # 使用AddDescription可以为不同类型的文档加入不同的描述 # Format: AddDescription "description" filename # #AddDescription "GZIP compressed document" .gz #AddDescription "tar archive" .tar #AddDescription "GZIP compressed tar archive" .tgz # # ReadmeName是服务器默认的README文件,并且会追加到目录列表的最后。 # HeaderName 是目录中需要预先显示内容的文件名。 ReadmeName README.html HeaderName HEADER.html # #IndexIgnore让Server在列出文件列表时忽略相应的文件,这里使用模式配置的文件定义文件名 # IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t # # 默认html的语言 # DefaultLanguage nl # #使用AddLanguage定义每个语言html的后缀 # Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl) # English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de) # Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja) # Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn) # Norwegian (no) - Polish (pl) - Portugese (pt) # Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv) # Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW) # AddLanguage ca .ca AddLanguage cs .cz .cs AddLanguage da .dk AddLanguage de .de AddLanguage el .el AddLanguage en .en AddLanguage eo .eo AddLanguage es .es AddLanguage et .et AddLanguage fr .fr AddLanguage he .he AddLanguage hr .hr AddLanguage it .it AddLanguage ja .ja AddLanguage ko .ko AddLanguage ltz .ltz AddLanguage nl .nl AddLanguage nn .nn AddLanguage no .no AddLanguage pl .po AddLanguage pt .pt AddLanguage pt-BR .pt-br AddLanguage ru .ru AddLanguage sv .sv AddLanguage zh-CN .zh-cn AddLanguage zh-TW .zh-tw # # LanguagePriority定义不同语言的优先级 # LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW # # ForceLanguagePriority allows you to serve a result page rather than # MULTIPLE CHOICES (Prefer) [in case of a tie] or NOT ACCEPTABLE (Fallback) # [in case no accepted languages matched the available variants] # ForceLanguagePriority Prefer Fallback # # 浏览器选择的默认标准编码 # AddDefaultCharset UTF-8 # # AddType可临时改变mime.types或者指定特殊文件的格式 # #AddType application/x-tar .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # Despite the name similarity, the following Add* directives have nothing # to do with the FancyIndexing customization directives above. # #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 .Z AddType 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 # # For files that include their own HTTP headers: # #AddHandler send-as-is asis # # For type maps (negotiated resources): # (This is enabled by default to allow the Apache "It Worked" page # to be distributed in multiple languages.) # 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 .shtml AddOutputFilter INCLUDES .shtml # # Action lets you define media types that will execute a script whenever # a matching file is called. This eliminates the need for repeated URL # pathnames for oft-used CGI file processors. # Format: Action media/type /cgi-script/location # Format: Action handler-name /cgi-script/location # # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # # Putting this all together, we can internationalize error responses. # # We use Alias to redirect any /error/HTTP_<error>.html.var response to # our collection of by-error message multi-language collections. We use # includes to substitute the appropriate text. # # You can modify the messages‘ appearance without changing any of the # default HTTP_<error>.html.var files by adding the line: # # Alias /error/include/ "/your/include/path/" # # which allows you to create your own set of files by starting with the # /var/www/error/include/ files and # copying them to /your/include/path/, even on a per-VirtualHost basis. # Alias /error/ "/var/www/error/" <IfModule mod_negotiation.c> <IfModule mod_include.c> <Directory "/var/www/error"> AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en es de fr ForceLanguagePriority Prefer Fallback </Directory> # ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var # ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var # ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var # ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var # ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var # ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var # ErrorDocument 410 /error/HTTP_GONE.html.var # ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var # ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var # ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var # ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var # ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var # ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var # ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var # ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var # ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var # ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var </IfModule> </IfModule> # # The following directives modify normal HTTP response behavior to # handle known problems with browser implementations. # BrowserMatch "Mozilla/2" nokeepalive BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 BrowserMatch "RealPlayer 4\.0" force-response-1.0 BrowserMatch "Java/1\.0" force-response-1.0 BrowserMatch "JDK/1\.0" force-response-1.0 # # The following directive disables redirects on non-GET requests for # a directory that does not include the trailing slash. This fixes a # problem with Microsoft WebFolders which does not appropriately handle # redirects for folders with DAV methods. # Same deal with Apple‘s DAV filesystem and Gnome VFS support for DAV. # BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully BrowserMatch "MS FrontPage" redirect-carefully BrowserMatch "^WebDrive" redirect-carefully BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully BrowserMatch "^gnome-vfs/1.0" redirect-carefully BrowserMatch "^XML Spy" redirect-carefully BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully # # Allow server status reports generated by mod_status, # with the URL of http://servername/server-status # Change the ".example.com" to match your domain to enable. # #<Location /server-status> # SetHandler server-status # Order deny,allow # Deny from all # Allow from .example.com #</Location> # # Allow remote server configuration reports, with the URL of # http://servername/server-info (requires that mod_info.c be loaded). # Change the ".example.com" to match your domain to enable. # #<Location /server-info> # SetHandler server-info # Order deny,allow # Deny from all # Allow from .example.com #</Location> # # Proxy Server directives. Uncomment the following lines to # enable the proxy server: # #<IfModule mod_proxy.c> #ProxyRequests On # #<Proxy *> # Order deny,allow # Deny from all # Allow from .example.com #</Proxy> # # Enable/disable the handling of HTTP/1.1 "Via:" headers. # ("Full" adds the server version; "Block" removes all outgoing Via: headers) # Set to one of: Off | On | Full | Block # #ProxyVia On # # To enable a cache of proxied content, uncomment the following lines. # See http://httpd.apache.org/docs/2.2/mod/mod_cache.html for more details. # #<IfModule mod_disk_cache.c> # CacheEnable disk / # CacheRoot "/var/cache/mod_proxy" #</IfModule> # #</IfModule> # End of proxy directives.
Section 3: Virtual Hosts
NameVirtualHost 192.168.191.150:80 #定义基于主机名的虚拟主机 <VirtualHost 192.168.191.150:80> #① ServerName www.cqy150.com DocumentRoot "/www/cqy150" </VirtualHost> <VirtualHost 192.168.191.150:80> #② ServerName www.chenqiyi150.com DocumentRoot "/www/chenqiyi150" </VirtualHost> <VirtualHost 192.168.191.151:80> #③ ServerName cqy151.com DocumentRoot "/www/cqy151" </VirtualHost> <VirtualHost 192.168.191.151:8080> #④ 需要Listen 8080 ServerName cqy1518080.com DocumentRoot "/www/cqy1518080" </VirtualHost>
定义虚拟主句得先取消中心主机,注释中心主机的DocumentRoot即可。
虚拟主机的定义:
<VirtualHost HOST>
....(可定义Section1和Section2的所有参数和语句)
</VirtualHost>
基于IP,HOST的写法 ②和③
IP1:80
IP2:80
基于端口,HOST的写法 ③和④
IP:80
IP:8080
基于域名,HOST的写法 ①和②
*:80
ServerName不同
location语句用法:
<Location "/images">
....
</Location>
Location定义的是url,而Directory定义的是文件系统
<Location /server-status> SetHandler server-status Order deny,allow Deny from all </Location>
拒绝所有访问/server-status