Tuesday, November 25, 2014

Apache HTTP Server

Apache HTTP Server

Apache is configured by the files in the conf subdirectory.
ThreadsPerChild: It tells the server how many threads it should use. This is the maximum number of connections the server can handle at once, so be sure to set this number high enough for your site if you get a lot of hits. The recommended default is ThreadsPerChild 150.
You can review the Windows Application Event Log by using the Event Viewer, e.g. Start - Settings - Control Panel - Administrative Tools - Event Viewer.
-------
install Apache as a Windows NT service from the command prompt at the Apache bin subdirectory:
httpd.exe -k install
--------
Removing an Apache service
httpd.exe -k uninstall
---------
If Apache is running as a service, stop it by opening another console window and entering:
httpd.exe -k shutdown
------
To run Apache from the command line as a console application:
httpd.exe
Press control-C to stop
---------
Running as a service should be preferred over running in a console window because this lets Apache end any current operations and clean up gracefully.
-------
to restart. It forces it to reread the configuration file. Any operations in progress are allowed to complete without interruption. Press Control-Break in the console window you used for starting Apache, or if the server is running as a service, enter:
httpd.exe -k restart
--------
specifies an absolute path to a particular configuration file:
httpd.exe -f "c:\my server files\anotherconfig.conf"

specifies a relative path to a particular configuration file:
httpd.exe -f files\anotherconfig.conf
-----------
If you don't specify a configuration file with -f or -n, Apache will use the file name compiled into the server, such as conf\httpd.conf. This built-in path is relative to the installation directory.
----------
After starting Apache (either in a console window or as a service) it will be listening on port 80.
-----
To connect to the server and access the default page, launch a browser and enter this URL:
http://localhost/
You may have to use this URL:
http://127.0.0.1/
If you happen to be running Apache on an alternate port, you need to explicitly put that in the URL:
http://127.0.0.1:8080/
-------
Addresses on the Web are expressed with URLs - Uniform Resource Locators - which specify a protocol (e.g. http), a servername (e.g. www.apache.org), a URL-path (e.g. /docs/current/getting-started.html), and possibly a query string (e.g. ?arg=value) used to pass additional arguments to the server.
A client (e.g., a web browser) connects to a server (e.g., your Apache HTTP Server), with the specified protocol, and makes a request for a resource using the URL-path.
---------
In order to connect to a server, the client will first have to resolve the servername to an IP address - the location on the Internet where the server resides. Thus, in order for your web server to be reachable, it is necessary that the servername be in DNS.
More than one hostname may point to the same IP address, and more than one IP address can be attached to the same physical server. Thus, you can run more than one web site on the same physical server, using a feature called virtual hosts.
-------
The default configuration file is usually called httpd.conf.
The configuration is frequently broken into multiple smaller files, for ease of management. These files are loaded via the Include directive.
The server is configured by placing configuration directives in these configuration files. A directive is a keyword followed by one or more arguments that set its value.
--------
Static content is things like HTML files, image files, CSS files, and other files that reside in the filesystem. The DocumentRoot directive specifies where in your filesystem you should place these files.
----------
Typically, a document called index.html will be served when a directory is requested without a file name being specified.
---------
The location of the error log is defined by the ErrorLog directive, which may be set globally, or per virtual host.
----------
When httpd starts, it binds to some port and address on the local machine and waits for incoming requests. By default, it listens to all addresses on the machine.
--------
The Listen directive tells the server to accept incoming requests only on the specified port(s) or address-and-port combinations.
For example, to make the server accept connections on both port 80 and port 8000, on all interfaces, use:
Listen 80
Listen 8000
-------
https is the default for port 443 and http the default for all other ports.
-----
You only need to set the protocol if you are running on non-standard ports. For example, running an https site on port 8443:
Listen 192.170.2.1:8443 https
-------
httpd configuration files contain one directive per line. The backslash "\" may be used as the last character on a line to indicate that the directive continues onto the next line. There must be no other characters or white space between the backslash and the end of the line.
Arguments to directives are separated by whitespace. If an argument contains spaces, you must enclose that argument in quotes.
Directives in the configuration files are case-insensitive, but arguments to directives are often case sensitive. Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on a line after a configuration directive. Blank lines and white space occurring before a directive are ignored, so you may indent directives for clarity.
--------
Only shell environment variables defined before the server is started can be used in expansions.
-------
You can check your configuration files for syntax errors without starting the server by using
apachectl configtest
or the -t command line option.
--------
To see which modules are currently compiled into the server, you can use the -l command line option. You can also see what modules are loaded dynamically using the -M command line option.
--------
Directives placed in the main configuration files apply to the entire server. If you wish to change the configuration for only a part of the server, you can scope your directives by placing them in <Directory>, <DirectoryMatch>, <Files>, <FilesMatch>, <Location>, and <LocationMatch> sections. These sections limit the application of the directives which they enclose to particular filesystem locations or URLs. They can also be nested, allowing for very fine grained configuration.
----------
httpd has the capability to serve many different websites simultaneously. This is called Virtual Hosting. Directives can also be scoped by placing them inside <VirtualHost> sections, so that they will only apply to requests for a particular website.
--------
httpd allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive. Directives placed in .htaccess files apply to the directory where you place the file, and all sub-directories. The .htaccess files follow the same syntax as the main configuration files. Since .htaccess files are read on every request, changes made in these files take immediate effect.
----------
In deciding what file to serve for a given request, httpd's default behavior is to take the URL-Path for the request (the part of the URL following the hostname and port) and add it to the end of the DocumentRoot specified in your configuration files. Therefore, the files and directories underneath the DocumentRoot make up the basic document tree which will be visible from the web.
For example, if DocumentRoot were set to
/var/www/html
 then a request for
http://www.example.com/fish/guppies.html
would result in the file
/var/www/html/fish/guppies.html
being served to the requesting client.

If a directory is requested (i.e. a path ending with /), the file served from that directory is defined by the DirectoryIndex directive. For example, if DocumentRoot were set as above, and you were to set:
DirectoryIndex index.html index.php
Then a request for http://www.example.com/fish/ will cause httpd to attempt to serve the file /var/www/html/fish/index.html. In the event that that file does not exist, it will next attempt to serve the file /var/www/html/fish/index.php.
--------
There are frequently circumstances where it is necessary to allow web access to parts of the filesystem that are not strictly underneath the DocumentRoot.
the Alias directive will map any part of the filesystem into the web space. For example, with
Alias /docs /var/web
the URL http://www.example.com/docs/dir/file.html will be served from /var/web/dir/file.html. The ScriptAlias directive works the same way, with the additional effect that all content located at the target path is treated as CGI scripts.
---------
Sometimes, it is desirable instead to inform the client that the requested content is located at a different URL, and instruct the client to make a new request with the new URL. This is called redirection and is implemented by the Redirect directive. For example, if the contents of the directory /foo/ under the DocumentRoot are moved to the new directory /bar/, you can instruct clients to request the content at the new location as follows:
Redirect permanent /foo/   http://www.example.com/bar/
This will redirect any URL-Path starting in /foo/ to the same URL path on the www.example.com server with /bar/ substituted for /foo/. You can redirect clients to any server, not only the origin server.
----------

No comments:

Post a Comment