Apache HTTP
This articles contains some information about handling the Apache HTTP server.
Table of Contents
The Apache HTTP server Ppoject is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT.
The Apache HTTP web server is still the most used web server worldwide.
On Ubuntu you can install the Apache HTTP server with the following command.
sudo apt-get install apache2
The Apache HTTP server provides a selection of Multi-Processing Modules (MPMs) which are responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests. On Ubuntu you can select one of them via one of the following commands.
# install the event MPM
# this is supposted to be less resource intensive
sudo apt-get install apache2-mpm-event
# install the worker MPM
sudo apt-get install apache2-mpm-worker
# install the worker MPM
sudo apt-get install apache2-mpm-prefork
The following describes the configuration files and commands for the Apache HTTP web server on Ubuntu.
The main configuration file for the Apache Http server is the
/etc/apache2/apache2.conf
file.
The error log of Apache is located in the
/var/log/apache2/error.log
file.
Apache HTTP can be running in different modes. These modes determine how the web requests of users are answered. These modes are called Multi-Processing-Module (MPMs). The selected mode is compiled into the server and can be seen via the following command.
apache2 -l
You find several sections in apache2.conf for configuring the different modules. Configure only the module which your server is using. For example if you see the modul "prefork.c" then you only need to configure the "mpm_prefork_module".
The following listing shows a configuration for a high traffic web server using the prefork module
<IfModule mpm_prefork_module> StartServers 20 MinSpareServers 20 MaxSpareServers 30 MaxClients 80 MaxRequestsPerChild 10000 </IfModule>
"error.log" contains the error messages of Apache. For example to check for too many simulatanous request you can run.
grep MaxClients /var/log/apache2/error.log // If there are problems you might get something like this: // server reached MaxClients setting, consider raising the MaxClients setting
Use the file ".htacess" to configure certain behavior of Apache HTTP. One major application of this file is to redirect URL to other URL's.
The following .htacess file reroutes that http://vogella.com to http://www.vogella.com. It also redirect access to a certain webpage (/articles/SpringFramework/article.html) to another webpage via a 301 redirect. The 301 redirect will tell search engines that this side has moved and is the recommended way to move webpages.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.vogella\.de$
RewriteRule ^(.*)$ http://www.vogella.com/$1 [L,R=301]
redirect 301 /articles/SpringFramework/article.html http://www.vogella.com/articles/SpringDependencyInjection/article.html
To optimize the download time of your webpages you can turn on gzip compression. This require the Apache module "mod_deflate" which can be installed by the following command:
a2enmod deflate /etc/init.d/apache2 restart
The compression can be activate via your ".htaccess" file.
# compress all text & html: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript
Virtual Hosts allow Apache2 to be configured for multiple sites that have separate configurations.
This allows you to have one Apache HTTP web server running on one IP serving multiple domains. Of course you still need to configure the DNS settings for the domains to map to the server but if you do this, you can
Under Ubuntu you create a configuration file in the
/etc/apache2/sites-available
folder, for example the www.vogella.com
.<VirtualHost 144.76.74.162:80> ServerName www.vogella.com ServerAdmin test@test.com ServerAlias vogella.de www.vogella.de vogella.com www.vogella.org vogella.org DocumentRoot /var/www/vhosts/vogella.com/documentroot <Directory /var/www/vhosts/vogella.com/documentroot> Options -Indexes AllowOverride all Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined CustomLog ${APACHE_LOG_DIR}/www.vogella.com-access.log combined </VirtualHost>
You enable sites (vhosts) with the following command.
#enable the vhost sudo a2ensite www.vogella.com #disable the vhost sudo a2dissite www.vogella.com
After enabling sites you have to restart your Apache HTTP server.
No comments:
Post a Comment