Skip to content

🌐 Understanding Web Servers and Apache HTTP Server


πŸ“˜ Table of Contents

  1. What Does Web Server Mean?
  2. What is the Purpose of Web Server Webpages?
  3. How to Install and Configure Apache and HTTP
  4. Httpd
  5. Configuration Files
  6. Managing the Service
  7. Log Files
  8. Handling the Firewall
  9. Lab: Common Uses for Apache and HTTP
  10. 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

  1. Install Apache HTTP Server:
    sudo apt update
    sudo apt install apache2
    

πŸ“ Configuration Files

  1. Main Configuration File:

  2. Path: /etc/apache2/apache2.conf

  3. Purpose: Contains global settings for Apache.

  4. Default Web Page:

  5. Path: /var/www/html/index.html
  6. Purpose: Default landing page served by Apache.

πŸ› οΈ Managing the Service

  1. Restart Apache:
sudo systemctl restart apache2
  1. Enable Apache to Start on Boot:
sudo systemctl enable apache2
  1. Check Apache Status:
    sudo systemctl status apache2
    

πŸ“œ Log Files

  1. Access Logs:

  2. Path: /var/log/apache2/access.log

  3. Purpose: Logs all incoming requests to the server.

  4. Error Logs:

  5. Path: /var/log/apache2/error.log
  6. 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:

  1. Check Firewall Status:
sudo ufw status
  1. Allow HTTP Traffic:

  2. To allow HTTP (port 80):

    sudo ufw allow 80/tcp
    
  3. To allow HTTPS (port 443) if using SSL:

    sudo ufw allow 443/tcp
    

  4. Reload Firewall Rules:

sudo ufw reload
  1. Verify Rules:
    sudo ufw status
    

4. Lab: Common Uses for Apache and HTTP

In this lab, we’ll cover several practical tasks with Apache and HTTP:

  1. Serve a Static Website:

  2. Place your HTML files in /var/www/html.

  3. Access the website via http://your-server-ip.

  4. Configure Virtual Hosts:

  5. Create a new virtual host configuration file in /etc/apache2/sites-available/. For example, your-site.conf:

    sudo nano /etc/apache2/sites-available/your-site.conf
    

  6. Enable the site:

    sudo a2ensite your-site.conf
    

  7. Check Server Status:

  8. View the status of the Apache service:

    sudo systemctl status apache2
    

  9. Set Up Directory Indexing:

  10. Modify /etc/apache2/mods-enabled/dir.conf to configure directory indexing:
    sudo nano /etc/apache2/mods-enabled/dir.conf
    
  11. 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.