🖥️ Web Servers
What is a web server? Learn about Apache and Nginx — the two most popular web servers powering the internet.
A web server is software (or the hardware running it) that serves web pages to users. When you type a URL in your browser, your browser sends an HTTP request to the web server, which responds by sending back the requested HTML, CSS, JS, images, etc.
The most popular web servers are Apache and Nginx. Together they power over 50% of all websites.
Both Apache and Nginx are popular open-source web servers, but they work differently:
- Apache — Launched 1995. Process-based model (one thread per request). Great compatibility, uses
.htaccessfiles for config per-directory. Default on most shared hosting. - Nginx (pronounced "engine-x") — Launched 2004. Event-driven, asynchronous model. Handles thousands of concurrent connections efficiently. Often used as a reverse proxy or load balancer.
In practice: Nginx is faster for serving static files and under high load. Apache is more flexible and easier to configure per-directory. Many servers use both — Nginx as reverse proxy, Apache as backend.
An .htaccess file is a configuration file used by Apache web servers. It lets you control server behaviour for a specific directory without editing the main server config.
Common uses:
- Redirecting URLs (e.g. redirect HTTP to HTTPS)
- Custom 404 error pages
- Password-protecting directories
- Blocking specific IP addresses
- Enabling URL rewriting (pretty URLs)
# Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
.htaccess) makes it a hidden file on Linux. Use your FTP client's "show hidden files" option to see it.