Web Services
Web Services covers Apache 2.4 and nginx: virtual hosting, TLS termination, reverse proxying, logging, and safe reloads. Expect configuration repair rather than memorizing every directive.
Core rules
- Apache reads a main file (
/etc/apache2/apache2.confor/etc/httpd/conf/httpd.conf) plus included vhosts. Debian enables sites witha2ensite; RHEL-family usesIncludeOptional conf.d/*.conf. - Name-based vhosts need
Listen 80,<VirtualHost *:80>,ServerName,ServerAlias, andDocumentRoot. Directory access uses<Directory>withRequire all granted; the first matching vhost is the default. - TLS vhosts listen on 443, set
SSLEngine on,SSLCertificateFile,SSLCertificateKeyFile, and oftenSSLCertificateChainFile. Modern Apache usesSSLProtocolandSSLCipherSuite. - nginx uses
serverblocks:listen 80; server_name app.example.com; root /var/www/app; location / { try_files $uri $uri/ =404; }. A reverse proxy addsproxy_pass http://127.0.0.1:3000;and forwardsHost,X-Real-IP,X-Forwarded-For, andX-Forwarded-Proto. - Squid controls access with
aclandhttp_access allow/deny;http_port 3128,cache_dir, andvisible_hostnameare common. Deny rules must come before broad allow rules. - Validate before reload:
apachectl configtestornginx -t; thensystemctl reload apache2ornginx.
Worked example
Publish app.example.com through nginx to a Node app on 127.0.0.1:3000. Create /etc/nginx/sites-available/app with server_name app.example.com;, location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }, symlink into sites-enabled, run nginx -t, reload. Reasoning: nginx terminates the client connection; the app sees the original Host and client address; without those headers redirects and logs show 127.0.0.1.
Traps
A missing Listen 443 leaves TLS unreachable; a cert/key mismatch or unreadable key stops startup; the first vhost captures unmatched names; nginx location precedence differs from Apache; and SELinux/AppArmor can return 403 even when file modes look correct. Always test config and check error_log.