Slide 01 / 08

🌐 Web Server Configuration

Apache & Nginx β€” P2P Teaching Session Β· Prepared by Mebell Angela Marquez Barro

🍽️ What is a Web Server?

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

πŸ” HTTP vs HTTPS

  • HTTP β€” Port 80, unencrypted ⚠️
  • HTTPS β€” Port 443, encrypted with SSL/TLS βœ…

Always prefer HTTPS. Without it, data is sent in plain text β€” anyone on the network can read it.

1

User types URL

2

DNS β†’ IP

3

HTTP Request

4

Server finds files

5

Sends response

6

Browser renders

Web ServerBest ForUsed At Hostinger
πŸ”΄ ApacheFlexibility, .htaccess, PHP sitescPanel VPS
🟒 NginxHigh traffic, reverse proxy, speedCloudPanel VPS, HWS
⚑ LiteSpeedSpeed + Apache compatibilityWeb & Cloud Hosting
🏠 HWSHostinger's Nginx forkAgency / H5G Hosting
Slide 02 / 08

πŸ”΄ Apache: The Flexible Classic

Process-based architecture β€” one thread per connection. Oldest and most widely used web server.

βœ… Strengths

  • .htaccess support (no restart needed)
  • Huge module ecosystem
  • Very well documented
  • Great for PHP sites & shared hosting

⚠️ Weaknesses

  • Slower under very high concurrent traffic
  • More memory usage per connection

πŸ“ Key Config Files

FilePurpose
/etc/apache2/apache2.confMain config
/etc/apache2/sites-available/Virtual hosts
.htaccessPer-directory overrides
mods-available/ssl.confSSL module

πŸ“ Virtual Host Example

<VirtualHost *:80>
  ServerName domain.tld
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>

πŸ“ Force HTTPS (.htaccess)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Slide 03 / 08

🟒 Nginx: The Speed Demon

Event-driven architecture β€” handles thousands of connections with a single process. Faster under high load.

βœ… Strengths

  • High concurrency with low memory
  • Excellent as reverse proxy
  • Faster at serving static files

⚠️ Weaknesses

  • No .htaccess support
  • Slightly steeper learning curve
  • Config changes require restart

πŸ“ Basic Server Block

server {
  listen 80;
  server_name domain.tld;
  root /var/www/html;
  index index.php index.html;


  location / {
    try_files $uri $uri/ =404;
  }
}

πŸ“ Reverse Proxy (Node.js on port 3000)

location / {
  proxy_pass http://localhost:3000;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For
    $proxy_add_x_forwarded_for;
}

πŸ’‘ What is a Reverse Proxy?

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).

Slide 04 / 08

⚑ Apache vs Nginx: Side-by-Side

Choose the right tool for the job.

FeatureπŸ”΄ Apache🟒 Nginx
ArchitectureProcess/thread per connectionEvent-driven (async)
Performance (high traffic)ModerateExcellent βœ…
.htaccess supportβœ… Yes❌ No
Reverse proxyPossible (mod_proxy)βœ… Built-in
Config styleDirective-basedBlock-based
Best forPHP sites, shared hostingHigh traffic, Node.js, microservices

πŸ”΄ Use Apache when…

  • You need .htaccess flexibility
  • You're on a cPanel-based VPS
  • Running PHP sites on shared-style hosting

🟒 Use Nginx when…

  • You need high performance & concurrency
  • You're running Node.js / Python apps
  • You need a reverse proxy setup
Slide 05 / 08

πŸ”’ SSL/HTTPS: Securing Your Site

SSL/TLS encrypts traffic between the browser and server. Without it, data is sent in plain text.

πŸ†“ Free SSL with Certbot (Let's Encrypt)

# For Nginx:
sudo certbot --nginx -d domain.tld


# For Apache:
sudo certbot --apache

πŸ”„ Auto-renew via cron (daily at noon)

0 12 * * * /usr/bin/certbot renew --quiet

πŸ›‘οΈ Enforce Modern TLS Only

# Apache (ssl.conf)
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1


# Nginx (server block)
ssl_protocols TLSv1.2 TLSv1.3;

⚠️ Why TLS 1.2+ only?

TLSv1 and TLSv1.1 are deprecated and have known vulnerabilities. Always enforce TLS 1.2 or 1.3 on production servers.

Slide 06 / 08

🏠 Hostinger Context

Which web server does each Hostinger plan use?

Hostinger PlanWeb ServerKey Note
Web & Cloud Hosting⚑ LiteSpeed.htaccess works βœ…
VPSπŸ”§ Your choiceFull control β€” Apache, Nginx, etc.
Agency / H5G🏠 HWS (Nginx fork).htaccess has NO effect ❌
CloudPanel VPS🟒 NginxManaged via CloudPanel UI
cPanel VPSπŸ”΄ ApacheManaged via cPanel

πŸ’‘ Common CS Scenarios

πŸ”§

.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.

Slide 07 / 08

πŸ” Troubleshooting Quick Reference

Always check logs first before making changes.

Error CodeMeaningCommon Fix
500 Internal Server ErrorMisconfigured .htaccess or PHP errorCheck .htaccess syntax, file permissions (644/755)
502 Bad GatewayUpstream app not runningCheck PHP-FPM or Node.js process
503 Service UnavailableServer overloaded or stoppedRestart web server, check resources
504 Gateway TimeoutUpstream app too slowIncrease timeout, optimize app

πŸ“‹ Check Logs

# Apache
tail -f /var/log/apache2/error.log


# Nginx
tail -f /var/log/nginx/error.log

πŸ§ͺ Test Config Before Restart

# Nginx
nginx -t


# Apache
apache2ctl configtest


# Restart
sudo systemctl restart nginx
sudo systemctl restart apache2
Slide 08 / 08

πŸ’¬ Discussion Questions

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?