Apache & Nginx β P2P Teaching Session Β· Prepared by Mebell Angela Marquez Barro
Software that receives HTTP/HTTPS requests from browsers and sends back web pages, files, or data.
Think of it like a restaurant:
You (browser) place an order β HTTP Request
Waiter (web server) fetches your files
Waiter brings back your food β Webpage
Always prefer HTTPS. Without it, data is sent in plain text β anyone on the network can read it.
User types URL
DNS β IP
HTTP Request
Server finds files
Sends response
Browser renders
| Web Server | Best For | Used At Hostinger |
|---|---|---|
| π΄ Apache | Flexibility, .htaccess, PHP sites | cPanel VPS |
| π’ Nginx | High traffic, reverse proxy, speed | CloudPanel VPS, HWS |
| β‘ LiteSpeed | Speed + Apache compatibility | Web & Cloud Hosting |
| π HWS | Hostinger's Nginx fork | Agency / H5G Hosting |
Process-based architecture β one thread per connection. Oldest and most widely used web server.
| File | Purpose |
|---|---|
/etc/apache2/apache2.conf | Main config |
/etc/apache2/sites-available/ | Virtual hosts |
.htaccess | Per-directory overrides |
mods-available/ssl.conf | SSL module |
<VirtualHost *:80>
ServerName domain.tld
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Event-driven architecture β handles thousands of connections with a single process. Faster under high load.
server {
listen 80;
server_name domain.tld;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
}
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
}
Nginx sits in front of your app and forwards requests to it. The user never talks to your app directly β Nginx handles port 80/443 and passes traffic to your app (e.g. Node.js on port 3000).
Choose the right tool for the job.
| Feature | π΄ Apache | π’ Nginx |
|---|---|---|
| Architecture | Process/thread per connection | Event-driven (async) |
| Performance (high traffic) | Moderate | Excellent β |
| .htaccess support | β Yes | β No |
| Reverse proxy | Possible (mod_proxy) | β Built-in |
| Config style | Directive-based | Block-based |
| Best for | PHP sites, shared hosting | High traffic, Node.js, microservices |
SSL/TLS encrypts traffic between the browser and server. Without it, data is sent in plain text.
# For Nginx:
sudo certbot --nginx -d domain.tld
# For Apache:
sudo certbot --apache
0 12 * * * /usr/bin/certbot renew --quiet
# Apache (ssl.conf)
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
# Nginx (server block)
ssl_protocols TLSv1.2 TLSv1.3;
TLSv1 and TLSv1.1 are deprecated and have known vulnerabilities. Always enforce TLS 1.2 or 1.3 on production servers.
Which web server does each Hostinger plan use?
| Hostinger Plan | Web Server | Key Note |
|---|---|---|
| Web & Cloud Hosting | β‘ LiteSpeed | .htaccess works β |
| VPS | π§ Your choice | Full control β Apache, Nginx, etc. |
| Agency / H5G | π HWS (Nginx fork) | .htaccess has NO effect β |
| CloudPanel VPS | π’ Nginx | Managed via CloudPanel UI |
| cPanel VPS | π΄ Apache | Managed via cPanel |
.htaccess not working on Agency plan? β It's HWS (Nginx-based). Enable .htaccess via hPanel toggle.
Can't edit httpd.conf on shared hosting? β Use .htaccess instead. Shared hosting doesn't give direct server config access.
502/503 error on VPS? β Check if the web server is running + check error logs.
Always check logs first before making changes.
| Error Code | Meaning | Common Fix |
|---|---|---|
| 500 Internal Server Error | Misconfigured .htaccess or PHP error | Check .htaccess syntax, file permissions (644/755) |
| 502 Bad Gateway | Upstream app not running | Check PHP-FPM or Node.js process |
| 503 Service Unavailable | Server overloaded or stopped | Restart web server, check resources |
| 504 Gateway Timeout | Upstream app too slow | Increase timeout, optimize app |
# Apache
tail -f /var/log/apache2/error.log
# Nginx
tail -f /var/log/nginx/error.log
# Nginx
nginx -t
# Apache
apache2ctl configtest
# Restart
sudo systemctl restart nginx
sudo systemctl restart apache2
Use these to check your student's understanding.
A customer's .htaccess redirect isn't working on an Agency plan. What do you check first?
What's the main architectural difference between Apache and Nginx?
A customer gets a 502 error after setting up a Node.js app behind Nginx. What are the likely causes?
Why can't customers on shared hosting edit httpd.conf directly?
When would you recommend Nginx over Apache for a VPS setup?
A customer's SSL certificate expired. Walk through how to renew it with Certbot.
What does server_tokens off do and why does it matter for security?