We downloaded a general Apache, if non-installed version, then we need to find Define SRVROOT in the httpd.conf file, Apache will configure it to the root directory of the current file path!
# 将SRVROOT配置为所在根目录
Define SRVROOT "D:\devGreenSoft\Apache24"
ServerRoot "${SRVROOT}"
Related modules | Related instructions |
---|---|
DocumentRoot
#在httpd.conf文件中为 所以默认该路径默认值为: Apache根目录/htdocs
DocumentRoot "${SRVROOT}/htdocs"
In determining what a given request file, httpd The default behavior is to obtain the requested URL-Path (URL portion of the host name and port on the back), and add it to DocumentRoot
the end of the specified configuration file. Therefore, DocumentRoot
constitute the basic document tree visible from the files and directories on the Web.
For example, if DocumentRoot
set, /var/www/html
then the request http://www.example.com/fish/guppies.html
will cause the file /var/www/html/fish/guppies.html
to be provided to the requesting client.
If the request directory (i.e., a path ending ... /
), from the file directory provided by the DirectoryIndex
definition instruction. For example, if you DocumentRoot
set up above, and you want to set:
DirectoryIndex index.html index.php
Then the request http://www.example.com/fish/
will result in httpd attempt to provide the documents /var/www/html/fish/index.html
. If the file does not exist, it will attempt to provide the next file /var/www/html/fish/index.php
.
If neither of these files exist, the next step is to try to provide a directory index, if mod_autoindex
loaded and configured to allow the directory index.
httpd also has virtual hosts , the host server may receive a plurality of requests. In this case, DocumentRoot
you can specify different for each virtual host, or instructions provided by the module mod_vhost_alias
may be used to dynamically determine an appropriate location from which to provide the content based on the IP address or host name requests.
The DocumentRoot
instructions in the main server configuration file ( httpd.conf
) is set, and possibly you create each additional settings on the virtual host once.
Files outside of DocumentRoot
Under normal circumstances, it must allow Web access to the file system is not in its section under stringent DocumentRoot
. httpd provides several different ways to achieve this goal. On Unix systems, symbolic links can bring other parts of the file system DocumentRoot
. For security reasons, only if the Options
provision of the relevant directory contains FollowSymLinks
or when, httpd will follow symbolic links SymLinksIfOwnerMatch
.
Alternatively, the Alias
instruction to any part of the file system is mapped to the Web space. For example,
Alias "/docs" "/var/web"
The URL http://www.example.com/docs/dir/file.html
provided from /var/web/dir/file.html
. The ScriptAlias
command works in the same way, additional effect is that all content located at the target path is treated as CGI scripts.
In the case of the need for additional flexibility, you can use AliasMatch
and ScriptAliasMatch
instructions based on regular expressions of powerful matching and replacement. E.g,
ScriptAliasMatch "^/~([a-zA-Z0-9]+)/cgi-bin/(.+)" "/home/$1/cgi-bin/$2"
The request is mapped http://example.com/~user/cgi-bin/script.cgi
to the path /home/user/cgi-bin/script.cgi
, and as CGI scripts generated files.
User directory
Conventionally, in Unix, a specific user 's home directory can be referred to ~user/
. The module mod_userdir
by allowing the use of the following URL to access files in each user's home directory, to extend this idea to the Web.
http://www.example.com/~user/file.html
For security reasons, direct access from the Web user's home directory is not appropriate. Therefore, the UserDir
directive specifies the directory under the user's home directory Web directory. Use the default settings Userdir public_html
, the above URL mapped to a file in the directory, for example /home/user/public_html/file.html
, where /home/user/
a user's home directory /etc/passwd
.
There are several other forms of Userdir
instruction, you can /etc/passwd
use the system does not contain the home directory location.
Some people find "~" symbol (usually encoded on the network %7e
) is very embarrassing, and prefer to use an alternate string to represent user directories. mod_userdir does not support this feature. However, if the user's home directory configured in a conventional manner, you can use the AliasMatch
command to achieve the desired effect. For example, to make http://www.example.com/upages/user/file.html
a map /home/user/public_html/file.html
, use the following AliasMatch
command:
AliasMatch "^/upages/([a-zA-Z0-9]+)(/(.*))?$" "/home/$1/public_html/$3"
URL redirection
The above discussed configuration instruction tells httpd acquires the content from a specific location in the file system and returns it to the client. Sometimes, I wish to inform the content requested by the client is in a different URL, and instruct the client to make a new request with the new URL. This is called redirection by Redirect
implementable instructions. For example, if the contents of the directory /foo/
under DocumentRoot
is moved to a new directory /bar/
, the client may indicate the request in the new location as follows:
Redirect permanent "/foo/" "http://www.example.com/bar/"
This will redirect any URL-Path /foo/
to www.example.com
the server /bar/
at the same URL as the alternative path /foo/
. You can redirect the client to any server, not just the original server.
httpd also provides RedirectMatch
instructions more complicated rewriting problems. For example, you want to request site's home page redirects to another site, but only retain all other requests, please use the following configuration:
RedirectMatch permanent "^/$" "http://www.example.com/startpage.html"
Or, to temporarily redirect all pages on a site redirected to a specific page on another site, use the following command:
RedirectMatch temp ".*" "http://othersite.example.com/startpage.html"
Reverse Proxy
httpd URL space also allows you to remote documents into the local server. This technique is called reverse proxy, because the Web server by obtaining documents from a remote server and returns it to the client to act as a proxy server. It is normal (forward) different agents, because for the client, the document appears to come from the reverse proxy server.
When a client requests in the following example, /foo/
the document directory, from server /bar/
to obtain these documents directory internal.example.com
, and returns them to the client as if they were from the local server.
ProxyPass "/foo/" "http://internal.example.com/bar/"
ProxyPassReverse "/foo/" "http://internal.example.com/bar/"
ProxyPassReverseCookieDomain internal.example.com public.example.com
ProxyPassReverseCookiePath "/foo/" "/bar/"
In the ProxyPass
configuration server to obtain the appropriate documents, and ProxyPassReverse
instructions from the redirect rewrite internal.example.com
, so for them the appropriate directory on the local server. Similarly, the back-end server settings ProxyPassReverseCookieDomain
and ProxyPassReverseCookiePath
rewrite cookie.
However, it is important to note links in the document will not be rewritten. Therefore, any absolute links internal.example.com
will cause the client to break through a proxy server and direct requests internal.example.com
. You can modify these pages provide links (and other content) in the use of the client mod_substitute
.
Substitute "s/internal\.example\.com/www.example.com/i"
For more complex rewriting of HTML and XHTML link, the mod_proxy_html
module can also be used. It allows you to create a URL mapping needs to be rewritten so that it can handle complex proxy program.
Rewrite engine
When you need a more powerful replacement, provided the rewrite engine mod_rewrite
might be useful. The command module may be used to decide where offers a feature request (e.g., browser type or source IP address). Further, mod_rewrite can use an external file or database to determine how to handle the request. Rewriting engine is capable of performing all three types of mappings discussed above: internal redirects (alias), and external redirect agent. In the detailed mod_rewrite documentation discusses a number of practical examples of using mod_rewrite.
file not found
Inevitably, the URL can not find the required matching files in the file system. This may be due to several reasons. In some cases, it may be to move documents from one location to another location results. In this case, it is best to use URL redirection to inform the new location of the client resources. In this way, even if the resource is in a new location, you can ensure that old bookmarks and links remain in force.
"File Not Found" Another common cause of the error is incorrectly entered URL directly, either directly in the browser or in HTML links. httpd module provides mod_speling
(sic) to help solve this problem. This module is activated, it will intercept "File Not Found" errors and look for resources with similar file names. If such a file is found, mod_speling sends an HTTP redirect to the client informing it that the correct location. If you find a few "off" file, it will provide customers with a list of available options.
Mod_speling a particularly useful feature is that it compares the file name without regard to case. This can help users understand the characteristics of the system URL is case sensitive and unix file system. However, in addition to the occasional URL correction, using mod_speling may add an additional load on the server, because "incorrect" behind each request URL redirection and a new request from the client.
mod_dir
Provided FallbackResource
, that can be used to map the virtual URI to real resources, and to provide services. This is mod_rewrite
very useful when implemented 'front controller' alternatives
Find what if all attempts fail, httpd will return an error page with HTTP status code 404 (file not found). The appearance of this page by a ErrorDocument
control command, in accordance with self- defined error response in a flexible manner discussed document custom .
Other URL mapping module
Other modules can be used for the URL mapping comprises:
mod_actions
- The MIME type or resource request method maps the request to a CGI script.mod_dir
- Provides a trailing slash to the basic mapping index file, for exampleindex.html
.mod_imagemap
- The user clicks on an HTML document embedded position of the image, map the request to the URL.mod_negotiation
- (such as language or content compression) to select the appropriate document in accordance with client preferences.