• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / nginx server tutorials (installation, configuration, performance tuning, security) / Apache vs nginx (connection handling, modules, memory usage)

Apache vs nginx (connection handling, modules, memory usage)

 

 

Cons of nginx:

  1. Limited modules
  2. everything has to code when compare to apache. (nightmare for new server admins)
  3. static modules (deploy only once while installing the server)
  4. not handles dynamic content it self (its a  pros)

Pros of Nginx

  1. less cpu & memory required to handle 1000+ concurrent connection (existed to address apache problems)

 

 

Table of Contents

Toggle
    • Why nginx created in 2004 2 version open source and premium nginx plus
    • Apache core architecture
  • Nginx core architecture
    • why people use nginx as proxy for apache?
    • .htaccess vs nginx server block
    • file system vs uri (request interpretation)
    • how litespeed faster than nginx and nginx plus

Why nginx created in 2004 2 version open source and premium nginx plus

C10K problem handling ten thousand concurrent connections
in Apache every connection handle by 1 worker that holds some memory, ex: 126MB if 500 Connection simultaneously Apache server has to
500*126MB= 63000 MB or 63GB. (it also holds Php as a module to control memory limit.
however, if 500 connections per seconds in reached in Apache you get message like max clients reached. or you may also install a beautiful module that only servers plain html page
in peak time
(Solution caching dynamic content as static (no request database) fastcgi or nginx as revere proxy)
page

Apache core architecture

apache-worker

mpm-prefork: process with 1 thread to handle 1 connection 1 process = (126+MB memory just on limit in php )
mpm-worker: process with 2 threads thread for 1 connection handling 2 connections by 1 process. but keep alive connections (idle which pages active in browser but no request from user also count as active connection holds some memory)
mpm-event: only uses threads for active connections. keep alive connection handles separately.

you have to select best for your server or websites need.

Note: we can’t limit apache process memory limit not like php or php-fpm but we can do it by limiting processes or threads)

//traffic = visitors >> connection. 100 real time visitors = not 100 active connections to db,php server proxy.

<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

<IfModule mpm_event_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
(based on above php -fpm pool manger set as on demand,dynamic,static in nginx)

 

Nginx core architecture

nginx-architecture

Nginx workers equal to cpu cores

user       www www;  ## Default: nobody
worker_processes  auto;  ## Default: 
error_log  logs/error.log;
pid        logs/nginx.pid;
worker_rlimit_nofile 8192;

events {
  worker_connections  4096;  ## Default: 1024
}

 

nginx workers auto =2
worker process = 1024 default
2*1024=2048 concurrent connections per seconds or 2 vcore server*big deal

single-threaded and processes use an asynchronous, non-blocking, event-driven connection handling algorithm.
not spawn process based on connection (every process = memory cpu holding)
2 process in nginx based on cores.
connection handling:
connections handled by the worker are placed within the event loop where they exist with other connections. Within the loop, events are processed asynchronously, allowing work to be handled in a non-blocking manner. When the connection closes, it is removed from the loop.

why people use nginx as proxy for apache?

nginx passes the connection to php-fpm then database
and waits until the connection process.

modules: apache modules easy install and configure dynamically and lot of features.
nginx modules can de deployer only once as static. however nginx introduced dynamic module
feature but it has to deploy with again fresh nginx installation(install fresh nginx with new module as dynamic in same /live or another server with same os and version of nginx then copy the module file into production server)

.htaccess vs nginx server block

.htaccess look for all servers files when a request process. (you can place own .htaccess to rewrite main server rules like wp .htaccess) but nginx only look specified directory
By not allowing directory overrides, Nginx can serve requests faster by
doing a single directory lookup and file read for each request (assuming that the file is found in the conventional directory structure).

nginx does not allow to overwrite rules every directory. so problems in shared hosting, (memory limit, compression,ssl etc)
cpanel only works with apache.

file system vs uri (request interpretation)

apache processes to file system while nginx to url

The try_files directive commonly uses the $uri variable, which represents the part of the URL after the domain name

and its new 2004 vs 1995 apache

how litespeed faster than nginx and nginx plus

Litespeed released on 2003 in enterprise version its got popular when its released 2014 openlitespeed free version

& 2017 litespeed cache plugin for wordpress.

same architecture as nginx. built in litespeed cache. while windows IIS server not free at all.

nginx vs apche vs iis

 

also know how to tune nginx performance

and improve mysql performance

Primary Sidebar

nginx server tutorials (installation, configuration, performance tuning, security)

  • Letsencrypt SSL Installation on apache/Nginx ubuntu / debian wordpress
  • fix error 520 522 524 on cloudflare wordpress godaddy nginx etc
  • nginx fastcgi cache wordpress how to configure
  • install LEMP Stack on 22.04 LTS Nginx MySQL PHP fpm #wordpress #digital ocean
  • Apache vs nginx (connection handling, modules, memory usage)
  • Pagespeed module install, configure, monitor, errors ft nginx &apache
  • nginx errors (504,502, 413, unable to start, syntax errors)
  • nginx conf explained best config file performance tuning tips nginx.conf location errors tutorial
  • use nginx as reverse proxy and load balancer for apache wordpress
  • nginx rewrite rules with examples 301 redirection
  • nginx modules list (enable, disable, upgrade, install dynamic module)
  • php fpm pool manager configuration settings based on server spike high cpu wordpress
  • php fpm restart nginx ubuntu enable status page, monitor etc
  • what is TTFB & how to Reduce it (server response time) Google pagespeed
  • letsencrypt install configure on ubuntu / debian nginx
  • Top 10 tips to improve nginx server security
  • nginx performance tuning connections, buffers file descriptors
  • enable brotli compression nginx brotli vs gzip
  • nginx installation on ubuntu 20.04 LTS
  • monitor nginx request with nginx status amplify datadog new relic
  • SSL faster reduce TLS hand shake improve https performance
  • nginx rate limiting explained by location time specific url
  • datadog nginx integration installation process
  • newrelic nginx integration process and errors fix and metrics
  • php fpm seems busy fixed warning and max children reached to handle max connections / requests
  • Php fpm configuration for 1000 concurrent connections server busy max children reached
  • php fpm ondemand vs dynamic vs Static (the dynamic pool problem)
  • nginx upstream response is buffered to a temporary file
  • php fpm install ubuntu 20.04 nginx
  • install phpmyadmin ubuntu nginx 22.04
  • upgrade php fpm ubuntu nginx 7.4 to 8.2
  • nginx add last modified header (remove, php wordpress)
  • php fpm dynamic pool manager settings
  • nginx fastcgi cache purge
  • nginx open file limit connections ulimits sysctl
  • php fpm high cpu usage WordPress 4 solutions nay work for you
  • nginx buffer size for wordpress
  • Cloudflare error code 524 nginx a timeout error occured
  • server configuration for 1000 concurrent users

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy