The Nginx-versus-Apache debate is older than most of the applications running on them. In practice, both are mature, fast and secure when configured well. The right choice depends on what your applications expect, who manages the server and whether you need per-directory configuration. This guide compares them honestly and shows production configurations for each, plus the hybrid setup many hosts use.
How They Differ
| Nginx | Apache httpd | |
|---|---|---|
| Architecture | Event-driven workers | MPMs: event (recommended), worker, prefork |
| Per-directory config | No (central config only) | Yes, .htaccess |
| PHP | Via PHP-FPM (FastCGI) | PHP-FPM via mod_proxy_fcgi, or mod_php with prefork |
| Static files | Very efficient | Efficient with event MPM |
| Reverse proxy and caching | Built-in, widely used | Available (mod_proxy, mod_cache) |
| Typical users | Modern stacks, proxies, high concurrency | Shared hosting, panels, legacy PHP apps |
The .htaccess Question
.htaccess lets each directory override settings, such as rewrites, redirects, access rules and caching headers, without touching the main configuration or reloading the server. That is convenient when many people manage their own sites. The cost is a file-system lookup for .htaccess files on every request and configuration scattered across directories. Nginx has no equivalent; rules must be translated into the server block. For a server you control, central configuration is cleaner; for multi-user hosting, .htaccess is often expected.
Production Nginx with PHP-FPM
server {
listen 443 ssl;
http2 on;
server_name example.com;
root /var/www/example.com/public;
index index.php;
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.(?!well-known) { deny all; }
}
Production Apache with the Event MPM and PHP-FPM
sudo a2dismod php8.3 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif rewrite headers http2 ssl
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/example.com/public
Protocols h2 http/1.1
<Directory /var/www/example.com/public>
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
SSLEngine on
# certificate lines added by Certbot
</VirtualHost>
The event MPM with PHP-FPM uses far less memory per connection than the prefork MPM with mod_php, and supports HTTP/2. Set AllowOverride None where you do not need .htaccess, to skip the per-request lookups.
Nginx in Front of Apache
A common hybrid: Nginx on ports 80/443 handles TLS, static files, caching and slow clients, and proxies dynamic requests to Apache on 127.0.0.1:8080, which keeps .htaccess support for applications that need it.
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~* \.(css|js|webp|png|jpg|svg|woff2)$ {
root /var/www/example.com/public;
expires 30d;
}
Enable mod_remoteip in Apache so logs and applications see the real client IP from X-Forwarded-For, trusting only 127.0.0.1. This is how many control panels are built; it adds one more service to manage, so use it when you need both behaviours.
Security Headers for Either Server
# Nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Frame-Options "SAMEORIGIN" always;
server_tokens off;
# Apache
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set X-Content-Type-Options "nosniff"
ServerTokens Prod
ServerSignature Off
Enable HSTS only after HTTPS works everywhere on the domain. A Content-Security-Policy adds strong protection but needs tailoring to each application.
Migrating from Apache to Nginx
- List every
.htaccessfile and the rules in it (rewrites, redirects, access denials, headers). - Translate them into Nginx
locationblocks; most applications document their Nginx configuration. - Test on a staging copy, checking redirects, pretty URLs, file uploads and protected directories.
- Switch over and keep Apache stopped but installed for quick rollback during the first days.
Pay special attention to security rules: an Apache deny from all in a directory's .htaccess silently disappears when Nginx serves that directory unless you replicate it.
Tuning Notes
- Nginx:
worker_processes auto, higherworker_connections, caching (see our web server tuning guide). - Apache event MPM: set
MaxRequestWorkers,ThreadsPerChildandServerLimitto match memory; check/server-status(restricted to localhost) under load. - PHP-FPM: the same tuning applies whichever web server sits in front (see our PHP applications guide).
Which Should You Choose?
| Situation | Recommendation |
|---|---|
| New application, you control the server | Nginx |
Application or plugins depend on .htaccess | Apache (event MPM + PHP-FPM), or Nginx in front of Apache |
| Many site owners editing their own rules | Apache |
| Reverse proxy for Node.js, Python or Go apps | Nginx (or Caddy) |
| Simplest automatic HTTPS | Caddy |
What Control Panels Use
Many hosting control panels run Apache, sometimes with Nginx in front as a proxy and cache, precisely because their users expect .htaccess to work. If you use a panel, follow its supported web server configuration rather than replacing components by hand, or upgrades may undo your changes. If you do not use a panel, either server is easy to manage directly.
Logs and Troubleshooting
Nginx logs to /var/log/nginx/ and Apache to /var/log/apache2/ on Debian and Ubuntu. Use a separate log file per site so problems are easy to isolate, include response times in the access log format, and check the error log first when a site returns 500 or 502 errors: a 502 from Nginx usually means PHP-FPM or the upstream application is down or overloaded, while Apache 500 errors often trace back to a faulty .htaccess rule.
Test Before Reloading
Both servers can validate configuration before applying it: sudo nginx -t and sudo apachectl configtest. Reload rather than restart to apply changes without dropping connections, and keep configuration in version control so any change can be reviewed and reverted.
Setup Checklist
- Choose Nginx, Apache (event MPM) or both, based on whether applications need
.htaccess. - Use PHP-FPM with a pool per site rather than
mod_php. - Enable HTTP/2, TLS with automatic renewal and security headers.
- Disable
.htaccesslookups where they are not needed. - Separate logs per site and test configuration before every reload.
In Short
Pick the server your applications expect, configure it with PHP-FPM, HTTP/2 and security headers, and test every change before reloading.
ServoMix Plans for This Workload
Either web server runs comfortably on every EPYC tier. Apache with mod_php or the prefork MPM uses more memory per connection, so pair it with PHP-FPM and the event MPM, or size up a tier if you must keep prefork.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| SMX vPro XS (AMD EPYC) | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹420/mo | Websites, small APIs, bots, staging and VPN servers | Order |
| SMX vPro S (AMD EPYC) | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹560/mo | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| SMX vPro M (AMD EPYC) | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹840/mo | Production databases, high-traffic sites, multi-container apps | Order |
| SMX vPro L (AMD EPYC) | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹1,120/mo | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Prices are monthly in INR as listed on the ServoMix store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Frequently Asked Questions
Is Nginx better than Apache?
Does Nginx support .htaccess?
Which Apache MPM should I use?
Can I run Nginx and Apache together?
How do I see real client IPs behind Nginx in Apache?
Is migrating from Apache to Nginx hard?
Which works better with WordPress?
What security headers should I add?
Does the web server choice affect PHP performance?
Which EPYC plan suits Nginx or Apache hosting?
Related Guides
Frequently Asked Questions
Is Nginx better than Apache?
Neither is universally better. Nginx excels at static files, proxying and many connections; Apache offers .htaccess flexibility. Both perform well when configured properly.
Does Nginx support .htaccess?
No. Rules must be translated into the central server configuration.
Which Apache MPM should I use?
The event MPM with PHP-FPM. Prefork with mod_php uses much more memory per connection and does not support HTTP/2 well.
Can I run Nginx and Apache together?
Yes. Nginx on ports 80/443 handles TLS, static files and caching and proxies dynamic requests to Apache on a local port.
How do I see real client IPs behind Nginx in Apache?
Enable mod_remoteip and trust X-Forwarded-For only from 127.0.0.1.
Is migrating from Apache to Nginx hard?
Usually not. Translate .htaccess rules into Nginx locations, test on staging, and pay attention to access-denial rules.
Which works better with WordPress?
Both. WordPress works on Nginx with a simple try_files rule; some plugins write .htaccess rules that need manual translation on Nginx.
What security headers should I add?
HSTS once HTTPS is complete, X-Content-Type-Options, Referrer-Policy, X-Frame-Options or a frame-ancestors policy, and hide server versions.
Does the web server choice affect PHP performance?
Little, when both use PHP-FPM. PHP-FPM settings, OPcache and caching matter far more.
Which EPYC plan suits Nginx or Apache hosting?
Any tier; size by the applications behind the web server, from 2 vCores / 8 GB for small sites to larger tiers for busy dynamic sites.
Your feedback helps us continuously improve ServoMix guides.
Know someone who may find this guide useful?
