What is Nginx? A beginner’s guide to web servers
What does Nginx do?
Nginx (pronounced “engine X”) is software that receives network requests and helps deliver websites and applications. It can send a saved file directly to a browser or forward a request to another program that creates a response. You do not need to write an application in Nginx to use it.
Imagine a small library website. A visitor wants its opening hours. The page already exists as a file, so Nginx can send that file without asking a separate application to generate it.
<!doctype html><html lang="en"> <meta charset="utf-8"> <title>ByteMind lab</title> <h1>Hello from ByteMind</h1></html>In the supplied lab, Nginx is configured to serve this file at http://127.0.0.1:18080/index.html. The browser would receive HTTP status 200 and display the heading Hello from ByteMind. This is a predicted result from the staged fixture, not a captured live response. 127.0.0.1 refers to the same computer or isolated environment, and 18080 is a lab port. You will configure the server in later chapters; no installation is required to understand this example.
Two ways to deliver a page
Static: Browser -> Nginx -> saved HTML fileDynamic: Browser -> Nginx -> application -> optional database Browser <- Nginx <- application responseA web server handles HTTP, the rules for exchanging web requests and responses. A reverse proxy receives requests on behalf of another server, forwards selected requests and returns the resulting responses. In the dynamic path, the application might look up today’s available books and generate a response. Nginx does not perform that business logic merely because it forwards the request.
Other jobs Nginx can perform
A load balancer distributes incoming requests across a group of backends, according to its configuration. A cache can reuse suitable stored responses instead of requesting them again. Both need deliberate configuration; neither automatically makes every application faster or reliable. With appropriate modules, Nginx can also proxy TCP, UDP or mail traffic. This course starts with HTTP on Nginx Open Source.
Where Nginx fits in an architecture
An application can listen for HTTP requests directly. Adding Nginx in front introduces a separate place to manage routing and delivery. A content delivery network (CDN) is a distributed delivery service that may cache responses near users; a single Nginx process is not a CDN. These roles can coexist. For a tiny internal service, direct hosting may be sufficient.
Nginx does not run PHP application code itself or replace a database. A PHP application needs a suitable runtime such as PHP-FPM. A separate application must enforce its own business rules and authorization.
Practice: choose the request path
A bakery has a fixed menu file and an endpoint that returns today’s remaining stock. Draw the path for each request. The menu can be served directly; the stock endpoint normally needs a backend that computes the current result. In the next lesson, learn how the browser identifies the server and requested resource.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx roles and request paths
Check the main concepts taught in this lesson.
Which request can Nginx normally answer by reading a file directly?
What is the main job of a reverse proxy?
A single Nginx server forwards requests to two equivalent backend services. Which role is this?
Which statement about adding Nginx to a small application is accurate?
Where should PHP application code execute in a typical Nginx/PHP-FPM design?