IT Course Directory: VMware, Linux, Networking, and Raspberry Pi

Apache HTTP Server Online Course: Installation, Hosting, Proxies, SSL, and Modules

Learn Apache HTTP Server administration on Linux and Windows, including installation, virtual hosts, websites, reverse and forward proxies, HTTPS, modules, logging, security, and troubleshooting.

Apache HTTP Server: What You Will Learn

Apache HTTP Server is open-source web server software. It receives HTTP or HTTPS requests, selects how each request should be handled, and returns a response. The response may contain a file from the server, an error message, or data received from another application.

This course covers Apache administration for static websites, multiple domains, HTTPS, forward proxies, reverse proxies, and backend applications. Examples use Ubuntu or Debian conventions where possible, with notes for Red Hat-family Linux and Windows.

1. Apache's Role in a Web Architecture

A web browser or another HTTP client sends a request to an IP address and port. Apache listens on that port, examines the request, and produces a response.

  • Server process: The running Apache service and its worker processes or threads.
  • Listener: A configured IP address and TCP port, commonly port 80 for HTTP and port 443 for HTTPS.
  • Request: Information from a client such as the method, path, hostname, headers, and optional body.
  • Response: A status code, response headers, and optional content.
  • DocumentRoot: The filesystem directory from which a website's files are served.
  • Directive: A configuration instruction such as Listen, ServerName, or DocumentRoot.
  • Module: A loadable component that adds features such as TLS, proxying, rewriting, or authentication.
  • Access log: A record of incoming requests and response details.
  • Error log: A record of startup, configuration, runtime, permission, proxy, and request-processing problems.

Apache can serve a static HTML file directly. It can also act as a front end for an application running on another port, or forward traffic to another server. The request path and hostname help Apache select the correct virtual host and processing rules.

Apache is a web server, not usually an application server. An application server runs business logic, such as a web application or API. Apache may pass requests to that application through a reverse proxy. A database server stores and queries structured data; Apache normally does not replace a database such as MySQL. A common architecture is browser to Apache, Apache to application server, and application server to database.

HTTP and HTTPS

HTTP is the application protocol used for web requests and responses. HTTPS is HTTP carried through a TLS-protected connection. TLS provides encryption in transit and helps the client verify the server's identity using a certificate.

Apache can terminate TLS itself, meaning that the client connects securely to Apache and Apache either serves the content or sends a separate request to a backend. It can also accept plain HTTP and redirect clients to HTTPS.

2. Prepare a Safe Practice Environment

Choose a local Linux machine, virtual machine, cloud server, dedicated host, or Windows workstation. A virtual machine is useful because configuration mistakes can be isolated and discarded. A public server requires careful firewall and access control planning.

Before installing Apache, identify the following:

  • The administrator account or root access needed to install packages and edit system configuration.
  • The server's IP address and the network interface on which Apache should listen.
  • The DNS name that should point to the server, or a temporary local hosts-file entry for testing.
  • Whether HTTP port 80 and HTTPS port 443 are allowed by the operating-system firewall, cloud security group, and any network firewall.
  • The location where website files, configuration files, certificates, and logs will be managed.

localhost and 127.0.0.1 refer to the local machine. A service bound only to the loopback interface cannot normally be reached from another machine. A TCP port identifies the service endpoint; opening a firewall port does not help if no process is listening there.

3. Install Apache

Ubuntu and Debian

Update package metadata, install Apache, and enable the service so it starts now and during future boots.

sudo apt update
sudo apt install apache2
sudo systemctl enable --now apache2
apache2 -v
sudo systemctl status apache2

Test the local HTTP endpoint:

curl -I http://localhost/

A successful response normally includes an HTTP status such as 200 OK. If a firewall is active, allow web traffic according to your firewall tool and security policy. On a public server, allow only the required ports, commonly TCP 80 and TCP 443.

Red Hat-family Linux

On Red Hat-family systems, the package and service are commonly named httpd. Package commands depend on the distribution release, but the general workflow is to install the httpd package, enable and start the service, test the configuration, and permit HTTP or HTTPS through the firewall.

sudo dnf install httpd
sudo systemctl enable --now httpd
httpd -v
sudo apachectl configtest
sudo systemctl status httpd

Some older systems use yum instead of dnf. Confirm the exact package and firewall commands for the installed release.

Windows

Download Apache from a trusted Apache distribution appropriate for Windows. Extract it to a controlled directory, inspect the supplied configuration, and use an elevated Command Prompt or PowerShell session. The executable is commonly named httpd.exe.

httpd.exe -v
httpd.exe -t
httpd.exe -k install
httpd.exe -k start

The Windows configuration generally resides below the Apache installation directory, often in a conf directory. Document roots and log locations are also commonly relative to that installation. Windows services, Windows Defender Firewall, and filesystem permissions must all permit the service to operate.

PlatformPackage or installation approachService nameConfiguration test commandPrimary configuration location
Ubuntu or Debianapt install apache2apache2apache2ctl configtest/etc/apache2/
Red Hat familyInstall the httpd package with the system package managerhttpdapachectl configtestUsually /etc/httpd/
WindowsExtract a trusted Apache distribution and configure httpd.exeApache Windows service or httpd.exehttpd.exe -tInstallation directory, commonly its conf subdirectory

4. Service Management and Directory Layout

A configuration change normally follows this sequence: edit a small, well-defined file; run a configuration test; inspect the result; reload Apache; and test the affected endpoint. A reload applies configuration without fully stopping the service. A restart stops and starts the service and may interrupt active connections.

sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl reload apache2
sudo systemctl enable apache2
sudo systemctl status apache2
sudo apache2ctl configtest

Use enable --now to enable and start a service in one operation. If a reload fails, do not repeatedly restart blindly. Read the error output, correct the configuration, test again, and keep a known-good copy for rollback.

Path or locationPurposeTypical platformAdministrative notes
/etc/apache2/apache2.confMain Apache configurationUbuntu or DebianIncludes other configuration files
/etc/apache2/sites-available/Available virtual-host definitionsUbuntu or DebianFiles are not normally active until enabled
/etc/apache2/sites-enabled/Enabled site definitionsUbuntu or DebianManaged with a2ensite and a2dissite
/etc/apache2/mods-available/ and /etc/apache2/mods-enabled/Module definitions and enabled modulesUbuntu or DebianManaged with a2enmod and a2dismod
/var/www/html/Common default document rootUbuntu or DebianUse a separate root for each real site
/var/log/apache2/access.logDefault access logUbuntu or DebianSite-specific logs are easier to analyze
/var/log/apache2/error.logDefault error logUbuntu or DebianCheck this during failed requests and reloads
/etc/httpd/Main configuration treeRed Hat familyOften includes conf.d and module configuration
Apache installation directory and logsConfiguration, content, and logsWindowsUse absolute paths or correct Windows path syntax

Ubuntu-like systems separate available files from enabled files, often using symbolic links. This makes it possible to disable a site without deleting its definition. Distribution layouts differ, so inspect the installed configuration before assuming a path.

5. Serve a Basic Website

Create a document root, place an index file in it, and grant Apache permission to traverse the parent directories and read the files. Keep application source code and private data outside the public document root where possible.

sudo mkdir -p /var/www/example.test/public
sudo sh -c 'printf "%s\n" "<h1>Example site</h1>" > /var/www/example.test/public/index.html'
sudo chown -R root:root /var/www/example.test
sudo find /var/www/example.test -type d -exec chmod 755 {} \;
sudo find /var/www/example.test -type f -exec chmod 644 {} \;

DirectoryIndex defines which file Apache looks for when a URL identifies a directory. Common choices include index.html and an application entry point. If no index file exists, Apache may return an error or show a directory listing depending on the Options setting. Disable directory listings when they are not required.

<Directory /var/www/example.test/public>
    Require all granted
    Options -Indexes +FollowSymLinks
    AllowOverride None
</Directory>

Use a browser or command-line client to test the site. The -I option requests headers only; a normal request retrieves the body.

curl -I http://server-address/
curl http://server-address/

6. Apache Configuration Fundamentals

Apache configuration consists of directives and containers. A directive has a name and arguments. A container, such as <VirtualHost> or <Directory>, applies settings to a selected scope.

Context means where a directive is allowed. Some directives work globally, some inside a virtual host, some inside a directory block, and some in per-directory files such as .htaccess. A directive in an invalid context causes a configuration error. Avoid enabling AllowOverride unless applications specifically require .htaccess; central configuration is usually easier to audit.

DirectivePurposeTypical contextExample use
ListenDefines an IP address and port on which Apache accepts connectionsGlobalListen 80
ServerNameSets the primary hostnameGlobal or virtual hostServerName example.test
ServerAliasAdds additional hostnames to a virtual hostVirtual hostServerAlias www.example.test
DocumentRootSpecifies the site's file directoryVirtual host or serverDocumentRoot /var/www/example.test/public
<Directory>Controls access and options for a filesystem directoryServer or virtual hostRequire all granted
DirectoryIndexNames default files for directory requestsServer, virtual host, or directoryDirectoryIndex index.html
ErrorLogChooses the error logServer or virtual hostErrorLog logs/site-error.log
CustomLogChooses the access log and formatServer or virtual hostCustomLog logs/site-access.log combined
IncludeLoads another configuration file or patternGlobalIncludeOptional conf.d/*.conf

Organize each site into a separate file, use separate logs, and make one logical change at a time. Before applying a change, copy the file or use version control. To roll back, restore the previous file, run the configuration test, and reload only after the test succeeds.

7. Name-Based Virtual Hosts

A VirtualHost is a configuration block for a site or endpoint. Name-based virtual hosting lets one IP address serve multiple websites. Apache compares the request's Host header with ServerName and ServerAlias values.

Create separate document roots and logs for two sites:

<VirtualHost *:80>
    ServerName example.test
    ServerAlias www.example.test
    DocumentRoot /var/www/example.test/public

    <Directory /var/www/example.test/public>
        Require all granted
        Options -Indexes +FollowSymLinks
        AllowOverride None
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.test-error.log
    CustomLog ${APACHE_LOG_DIR}/example.test-access.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerName second.test
    DocumentRoot /var/www/second.test/public

    <Directory /var/www/second.test/public>
        Require all granted
        Options -Indexes
        AllowOverride None
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/second.test-error.log
    CustomLog ${APACHE_LOG_DIR}/second.test-access.log combined
</VirtualHost>

On Ubuntu or Debian, save the definitions under /etc/apache2/sites-available/ and enable them:

sudo a2ensite example.test.conf
sudo a2ensite second.test.conf
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

For a real deployment, create DNS records that point each hostname to the server. For a lab, add the names and server IP address to the client's hosts file. The default virtual host is used when no hostname matches, so an unexpected default page often indicates a missing DNS or hosts-file entry, a disabled site, or an incorrect hostname.

Test matching without relying on DNS by sending an explicit Host header:

curl -H 'Host: example.test' http://server-address/
curl -H 'Host: second.test' http://server-address/

8. Forward and Reverse Proxying

CharacteristicForward proxyReverse proxy
RepresentsClients inside a networkServers or applications behind Apache
Connection directionClient asks Apache to reach an external destinationClient asks Apache for a site; Apache contacts a backend
Typical purposeControlled outbound access, filtering, or auditingTLS termination, routing, central access control, and application publishing
Main riskAn unrestricted installation becomes an open proxyIncorrect routing, exposed backends, or lost client information

Forward proxy

In a forward-proxy arrangement, clients explicitly use Apache as an intermediary to reach other destinations. Enable this only when there is a clear operational need. ProxyRequests On enables forward proxy behavior; it must be paired with strict client restrictions.

<IfModule mod_proxy.c>
    ProxyRequests On
    <Proxy "*">
        Require ip 192.0.2.0/24
    </Proxy>
</IfModule>

Never expose an unrestricted forward proxy to the internet. Restrict source addresses, firewall access to the proxy port, monitor usage, and disable forward proxying when it is not needed. A basic client test uses a client configured to use the Apache proxy, followed by a request to a permitted destination. Test from an approved network only.

Reverse proxy

A reverse proxy receives a normal request from a browser and sends it to a backend application. The backend may listen only on 127.0.0.1 and therefore remain inaccessible directly from the public network.

<VirtualHost *:80>
    ServerName app.example.test

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/

    ErrorLog ${APACHE_LOG_DIR}/app-proxy-error.log
    CustomLog ${APACHE_LOG_DIR}/app-proxy-access.log combined
</VirtualHost>

ProxyPass maps an incoming path to a backend URL. ProxyPassReverse adjusts redirect headers returned by the backend so that clients continue to use the public URL. ProxyPreserveHost On passes the original hostname when the application needs it. Applications may also need forwarded client and protocol headers, but configure those deliberately and ensure the application trusts them only from Apache.

Enable the common HTTP proxy modules on Ubuntu or Debian:

sudo a2enmod proxy proxy_http
sudo apache2ctl configtest
sudo systemctl reload apache2
curl -I http://127.0.0.1:3000/
curl -I http://app.example.test/

Basic load balancing requires additional proxy modules and a defined backend set. Consider health checks, session handling, timeouts, failure behavior, and whether a dedicated load balancer is more suitable.

9. SSL/TLS and HTTPS

HTTPS protects the connection from eavesdropping and helps the browser verify that it is communicating with the intended hostname. A TLS certificate identifies the server name and is paired with a secret private key. The private key must not be readable by untrusted users or exposed in a public document root.

Use a self-signed certificate for a controlled lab. Browsers will warn because they cannot establish trust through a recognized certificate authority. Production websites should use a publicly trusted certificate whose names match the site and should have a documented renewal process.

sudo openssl req -x509 -newkey rsa:2048 -nodes -days 365 \
  -keyout /etc/ssl/private/example.test.key \
  -out /etc/ssl/certs/example.test.crt

On Ubuntu or Debian, enable SSL and create an HTTPS virtual host:

sudo a2enmod ssl
sudo a2enmod headers
sudo apache2ctl configtest
sudo systemctl reload apache2
<VirtualHost *:443>
    ServerName example.test
    DocumentRoot /var/www/example.test/public

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/example.test.crt
    SSLCertificateKeyFile /etc/ssl/private/example.test.key

    <Directory /var/www/example.test/public>
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.test-ssl-error.log
    CustomLog ${APACHE_LOG_DIR}/example.test-ssl-access.log combined
</VirtualHost>

When HTTPS is working, redirect the HTTP virtual host if plain HTTP is not required for another purpose:

<VirtualHost *:80>
    ServerName example.test
    Redirect permanent / https://example.test/
</VirtualHost>

Verify with a browser and command-line tools:

curl -I https://example.test/
curl -vk https://example.test/

The -k option bypasses certificate trust checks and is suitable only for controlled testing. A certificate warning can result from a self-signed certificate, a hostname mismatch, an expired certificate, an incorrect certificate path, a missing SSL module, or unsuitable key permissions. Plan renewal before certificates expire and verify that automated renewal updates Apache safely.

10. Apache Modules

Apache's functionality is modular. A module can add protocol support or processing features without making every installation load every capability. Load only the modules required by the deployment, because fewer enabled components reduce complexity and the available attack surface.

ModuleCapabilityTypical use caseSecurity or operational consideration
mod_sslTLS and HTTPSSecure virtual hostsProtect keys and maintain certificate renewal
mod_proxyProxy frameworkForward or reverse proxyingDo not enable unrestricted forward proxying
mod_proxy_httpHTTP backend proxyingProxying applications on ports such as 3000 or 8080Check backend access and timeout behavior
mod_rewriteURL and request rewritingRedirects and application routingComplex rules can create loops or bypass intended paths
mod_headersRequest and response headersSecurity headers and proxy metadataDo not blindly trust client-supplied forwarding headers
mod_authz_hostHost and IP authorizationRestrict directory or proxy accessReview network ranges carefully
mod_deflateResponse compressionReducing transfer sizeMeasure CPU use and avoid compressing unsuitable content
mod_statusServer activity informationOperational monitoringRestrict the status endpoint to administrators

Find loaded modules and enable common modules on Ubuntu or Debian:

sudo apache2ctl -M
sudo a2enmod ssl
sudo a2enmod proxy proxy_http
sudo a2enmod rewrite
sudo a2enmod headers
sudo systemctl reload apache2

Some modules depend on other modules. If Apache reports an unknown directive, identify the module that provides it, enable that module, run a configuration test, and reload only after the test succeeds. Disable unused modules with the distribution's module-management command after confirming that no active site depends on them.

11. Logging, Monitoring, and Maintenance

Start troubleshooting with evidence. Access logs show what clients requested and the resulting status code. Error logs explain configuration, permission, file, TLS, and proxy failures.

sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/error.log
sudo journalctl -u apache2 -n 100 --no-pager
sudo ss -ltnp | grep -E ':80|:443'

Use separate access and error logs per virtual host where practical. This makes it easier to identify which site generated a request and prevents unrelated traffic from obscuring a failure. Configure and verify log rotation so logs do not consume all available disk space. Apply operating-system and Apache security updates regularly, then use a configuration test and a controlled reload or restart.

Status codeMeaningLikely causeInitial diagnostic action
200Successful responseRequested resource was servedConfirm the response content and selected virtual host
301 or 302RedirectHTTP-to-HTTPS rule or application redirectInspect the Location header and check for loops
403ForbiddenDirectory rule or filesystem permissions deny accessReview the Directory block and error log
404Not FoundMissing file, wrong document root, route, or proxy pathConfirm the URL, matching virtual host, and backend route
500Internal Server ErrorServer-side rule or application failureRead the error log and inspect application output
502Bad GatewayApache cannot obtain a valid backend responseTest the backend directly and inspect proxy errors
503Service UnavailableStopped or overloaded backend, or unavailable serviceCheck backend status, capacity, and proxy configuration

12. Security and Operational Practices

  • Keep the operating system, Apache packages, modules, and backend applications updated.
  • Use a firewall to expose only required services, normally TCP 80 and 443 for a public web server.
  • Protect private keys with restrictive ownership and permissions. Never place them below a public document root.
  • Grant Apache only the filesystem access it needs. Avoid broad write permissions on website directories.
  • Disable directory listing unless it is an intentional feature.
  • Disable unused sites and modules, especially proxy functionality that is not required.
  • Restrict forward proxy clients by source network and firewall policy. An open proxy can be abused to hide attacks or relay unwanted traffic.
  • Separate site configurations, document roots, and logs to simplify auditing and incident response.
  • Run apache2ctl configtest, apachectl configtest, or httpd.exe -t before every production reload.
  • Keep a tested rollback copy of configuration files and record what changed.
  • Limit administrative endpoints such as server-status to trusted addresses.
  • Use trusted certificates in production and monitor expiry dates.

13. Troubleshooting Workflow

When a browser cannot connect, first check whether Apache is running and listening. Then test locally, verify the firewall and cloud security rules, and confirm DNS resolution. A local curl success combined with remote failure usually points to networking, firewall, binding, or DNS rather than the document root.

When a reload fails, run the configuration test and read the system journal and error log. Typical causes are a syntax error, an unknown directive from a disabled module, a malformed virtual host, or a certificate path that does not exist.

If the default site appears instead of the intended site, verify that the site is enabled, the ServerName and ServerAlias values match the client's hostname, and DNS or the local hosts file points to the correct server. Test with an explicit Host header.

A 403 Forbidden response commonly means that Apache's Directory rules do not grant access, the Apache user cannot read the file, or a parent directory cannot be traversed. A 404 Not Found response commonly means that the document root, requested file, virtual-host mapping, or proxy route is wrong.

A 502 or 503 reverse-proxy response means that the backend should be examined directly. Confirm that the application is running, that its address and port match ProxyPass, that required proxy modules are loaded, and that local firewall or bind-address settings permit Apache to connect.

For HTTPS failures, inspect certificate names, expiration, trust chain, certificate and key paths, key permissions, the SSL module, and the TLS-related error log. For an unexpectedly exposed forward proxy, turn off ProxyRequests if it is unnecessary, add restrictive Require rules, and review firewall policy immediately.

14. Practical Administration Exercises

  1. Install and verify Apache: Install it on Ubuntu or Debian, confirm the version, check service status, verify a listener on port 80, and replace the default page with a simple HTML page.
  2. Deploy a static site: Create a dedicated document root, configure a directory block, set safe ownership and permissions, create separate logs, and test with both a browser and curl.
  3. Host two domains: Create two virtual hosts with different document roots and logs. Use local hosts-file entries or DNS, then test each one with an explicit Host header.
  4. Create HTTPS: Generate a self-signed certificate for a lab, configure an HTTPS virtual host, verify the certificate warning is expected, and redirect HTTP to HTTPS.
  5. Reverse proxy an application: Run or use an application on port 3000 or 8080, enable the required proxy modules, configure ProxyPass and ProxyPassReverse, and compare direct-backend and Apache responses.
  6. Build a restricted forward proxy: Enable forward proxying only in an isolated lab, restrict it to an approved test network, verify permitted access, and then disable it when finished.
  7. Diagnose a failed deployment: Intentionally test a bad document root, missing module, wrong permission, stopped backend, or incorrect hostname. Use configuration testing, service status, listening-port checks, and logs to locate the cause.

15. Exam-Relevant Summary

  • DocumentRoot identifies where Apache looks for site files; a Directory block controls access and options for that filesystem path.
  • ServerName is the primary hostname for a virtual host, while ServerAlias adds matching names.
  • Name-based virtual hosts allow multiple websites to share an address and are selected using the request hostname.
  • A forward proxy represents clients reaching external destinations; a reverse proxy represents backend servers receiving published requests.
  • ProxyRequests On enables forward-proxy behavior and must never be left unrestricted on a public network.
  • ProxyPass sends a public path to a backend, while ProxyPassReverse adjusts backend redirects for clients.
  • Always validate configuration before reloading. A syntax test does not prove that DNS, permissions, firewall rules, or backend availability are correct.
  • Access logs show requests and status codes; error logs show configuration, runtime, permission, TLS, and proxy problems.
  • A certificate is public identity information; its paired private key is secret and requires strict protection.
  • Modules provide optional capabilities. Enable required dependencies and disable functionality that the deployment does not use.

For hands-on follow-up, use the Apache course activity and review the Apache course curriculum. Related study includes MySQL for database-backed applications, Nmap for network verification, and Splunk for log analysis.