Apache HTTP Server Practical Tutorial
As the first choice for getting started with Web development, the old open source server Apache HTTP Server (hereinafter referred to as Apache) still maintains more than 30% of the global market share due to its cross-platform, modular, stable and easy-to-use features. This article focuses on core scenarios commonly used by novices/small teams and uses streamlined steps and code to help you get started quickly.
1. Quick installation and startup
We cover the three most mainstream environments: Linux, Docker and Docker Compose (for easy unified management).
1.1 Linux native installation
Linux is Apache's golden partner. Different distributions only need to adjust the package manager.
Ubuntu/Debian system
CentOS/RHEL system
After successful installation, access the server IP (port 80) and you will see Apache’s default welcome page!
1.2 Docker/Docker Compose one-click deployment
Suitable for local testing, development environment isolation, or quickly building a microservice gateway.
Docker single container
Access after startuphttp://localhost:8080That’s it, localhtml/The files in the directory will be directly used as the content of the Web root directory.
2. Core basic configuration
The core configuration of Apache is divided into global configuration and virtual host configuration. The paths for Linux native and Docker deployment are different:
2.1 Key optimization of global configuration
There is no need to make major changes to the global configuration. Newbies only need to adjust these three places to improve security and ease of use:
2.2 Virtual host configuration (most commonly used!)
Virtual host allows one server to host multiple domain names/sites. We use Ubuntu as an example to configure HTTP basic virtual host.
Step 1: Create site directory and test files
Test home page content:
Step 2: Write virtual host configuration
Step 3: Enable configuration and reboot
3. Practical advanced configuration
3.1 Let's Encrypt Free SSL Certificate (Mandatory HTTPS)
HTTPS is now standard, and Let's Encrypt provides free 90-day auto-renewing certificates withcertbotTools are available with just one click.
Ubuntu installation and configuration
implementcertbotYou will be prompted to enter your email address and agree to the agreement. Finally, you will be asked whether to force HTTP to jump to HTTPS. Select2: RedirectThat’s it!
3.2 URL rewriting (SEO friendly)
use.htaccessImplement URL beautification, such asarticle.php?id=123Change to/article/123。
Step 1: Create in the site root directory.htaccess
Step 2: Write rewrite rules
3.3 Gzip compression (improve loading speed)
Compressing HTML, CSS, JS and other text resources can reduce the transmission volume by 60%-80%. Add directly to the global configuration or virtual host configuration:
4. Summary of best practices
- Security first: Hide the version number, force HTTPS, prohibit listing of the production environment directory, and use firewalls to restrict ports.
- Performance first: Enable KeepAlive, Gzip compression, and static resource caching (you can use
mod_expiresAdd to.htaccessor virtual host). - Standardized Management: The virtual host is named according to the domain name and the syntax is verified before configuration (
apache2ctl configtest), graceful restart after deployment (systemctl reload apache2)。 - Log Monitoring: Check the error log regularly, use
tail -fObserve traffic volume and abnormal requests in real time.
Although Apache does not have the high concurrency performance of Nginx, its modular architecture and rich documentation are more friendly to novices and are suitable for deploying small and medium-sized static sites, blogs or as a simple reverse proxy.

