Docs / Web Servers / Apache Virtual Hosts Configuration Guide

Apache Virtual Hosts Configuration Guide

By Admin · Apr 2, 2026 · Updated Apr 23, 2026 · 4 views · 3 min read

Getting apache right from the start saves hours of debugging later. In this comprehensive guide, we'll cover everything from initial setup to production-ready configuration, including virtual-hosts and configuration considerations.

Prerequisites

  • A web server installed (Nginx or Apache)
  • A registered domain name (for public-facing services)
  • A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
  • Basic familiarity with the Linux command line
  • Root or sudo access to the server

Server Installation

The apache configuration requires careful attention to resource limits and security settings. On a VPS with limited resources, it's important to tune these parameters according to your available RAM and CPU cores.


# /etc/nginx/sites-available/apache.conf
server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.

Security Implications

The virtual-hosts component plays a crucial role in the overall architecture. Understanding how it interacts with apache will help you make better configuration decisions.

Virtual Host Configuration

It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.


# Test and reload Nginx configuration
sudo nginx -t
sudo systemctl reload nginx

# Check access and error logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log

Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.

SSL/TLS Setup

When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.


# Install Nginx with modules
sudo apt update
sudo apt install -y nginx

# Enable the site
sudo ln -s /etc/nginx/sites-available/apache.conf /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Wrapping Up

Following this guide, your apache setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.

Was this article helpful?