Nginx doesn't serve php. Apache doesn't either. At the very basic level, they are similar to the router in Laravel, Angular.js and many other frameworks. Similar to the way you use the before function in Laravel Routes to call an auth utility etc., these servers can call a service executable such as php, java or python to handle file requests based on extension. Nginx and Apache do it quite differently though. Nginx uses something called an event model with only one process. Apache (with a few exceptions) creates a new thread for each task. I explained this at a conference a few months ago as this:
Imagine you are tasked with managing a huge Whackamole event. There are 100 moles popping up everywhere.
As the manager, you have two choices of how to handle this.
- Hire 20 people (say at 10.00 per hour each). There sole job is to watch only 5 holes each. If a mole pops up whack it. If no moles pop up, you still have to pay each one (you know about labor law right?).
- Hire the world renowned "Evil Eye Mole Whacker". He charges 30.00 and hour but his claim to fame is "No mole has ever gotten past me". You can bet that he will be very busy but, sure to his reputation, no mole will ever see the light of day on his watch.
Evented models like Nginx and Javascript have a very good place where there sole job is to just listen for things and call a process or function to do its thing.
You might ask "Why isn't everything event based then?". Well, if you have a complicated application with many moving parts with many inter-dependencies, threading can help keep a little order in the game.
I do find it a little amusing when I see performance "comparisons" of things like node.js, php, asp.net, java etc. Everyone sets up one operation such as a Fibonacci or factorial calculation. They like to quote reqests per second on the evented models as being so much higher. There are not a lot of real world uses for Fibonacci though. Throw in a little complication like authentication and maybe a many to many relationship however and the picture changes very quickly.