π Understanding Web Servers and Apache HTTP Server
π Table of Contents
- What Does Web Server Mean?
- What is the Purpose of Web Server Webpages?
- How to Install and Configure Apache and HTTP
- Httpd
- Configuration Files
- Managing the Service
- Log Files
- Handling the Firewall
- Lab: Common Uses for Apache and HTTP
- Common Options for Apache and HTTP
1. What Does Web Server Mean?
A web server is a software application or hardware device that serves web pages to users over the internet or intranet. It processes incoming requests from clients (typically web browsers) and delivers the requested content.
Key Functions of a Web Server:
- Receive Requests: Handles HTTP requests from clients.
- Serve Web Pages: Delivers static or dynamic web pages to clients.
- Execute Scripts: Runs server-side scripts to generate dynamic content.
- Manage Sessions: Handles user sessions and maintains state across requests.
2. What is the Purpose of Web Server Webpages?
The purpose of web server webpages is to deliver content and provide services to users. They can be:
Common Purposes Include:
- Hosting Websites: Displaying HTML, CSS, and JavaScript files for user access.
- Serving Applications: Running and interacting with web applications and databases.
- Providing APIs: Offering endpoints for third-party applications to interact with.
- Content Delivery: Delivering media files such as images, videos, and documents.
3. How to Install and Configure Apache and HTTP
π¦ Httpd
httpd
is the Apache HTTP server daemon. Below are the steps to install and configure Apache:
Installation
- Install Apache HTTP Server:
π Configuration Files
-
Main Configuration File:
-
Path:
/etc/apache2/apache2.conf
-
Purpose: Contains global settings for Apache.
-
Default Web Page:
- Path:
/var/www/html/index.html
- Purpose: Default landing page served by Apache.
π οΈ Managing the Service
- Restart Apache:
- Enable Apache to Start on Boot:
- Check Apache Status:
π Log Files
-
Access Logs:
-
Path:
/var/log/apache2/access.log
-
Purpose: Logs all incoming requests to the server.
-
Error Logs:
- Path:
/var/log/apache2/error.log
- Purpose: Logs server errors and issues.
π Handling the Firewall
To access your Apache server from a browser, you need to ensure that your firewall allows HTTP traffic. Hereβs how to configure your firewall:
- Check Firewall Status:
-
Allow HTTP Traffic:
-
To allow HTTP (port 80):
-
To allow HTTPS (port 443) if using SSL:
-
Reload Firewall Rules:
- Verify Rules:
4. Lab: Common Uses for Apache and HTTP
In this lab, weβll cover several practical tasks with Apache and HTTP:
-
Serve a Static Website:
-
Place your HTML files in
/var/www/html
. -
Access the website via
http://your-server-ip
. -
Configure Virtual Hosts:
-
Create a new virtual host configuration file in
/etc/apache2/sites-available/
. For example,your-site.conf
: -
Enable the site:
-
Check Server Status:
-
View the status of the Apache service:
-
Set Up Directory Indexing:
- Modify
/etc/apache2/mods-enabled/dir.conf
to configure directory indexing: - Add or adjust the
DirectoryIndex
directive to list index files.
5. Common Options for Apache and HTTP
Option | Description |
---|---|
apache2.conf |
Main Apache configuration file. |
ports.conf |
Configures listening ports for Apache. |
sites-available/ |
Directory for available site configurations. |
sites-enabled/ |
Directory for enabled site configurations. |
mods-enabled/ |
Directory for enabled modules. |
a2ensite |
Command to enable a site. |
a2dissite |
Command to disable a site. |
a2enmod |
Command to enable a module. |
a2dismod |
Command to disable a module. |