What is Nginx?
Author: Domeny.ForSale editorial team Published
In brief: Nginx is server software that receives requests from browsers and delivers website files or forwards traffic to an application. It can also handle encrypted HTTPS connections, distribute traffic across servers and cache copies of responses. On managed hosting, the provider usually handles it; on your own server, configuring it may be your responsibility.
What role does Nginx play when you open a website?
Nginx, pronounced “engine-x”, is primarily an HTTP server, a program that handles the communication used to retrieve web pages. It should not be confused with a physical server or a virtual machine: Nginx runs on such a computer alongside other programs.
When you enter a website address, DNS — the system that maps domain names to network addresses — helps the browser find the server. The browser establishes a connection and sends a request, for example for the home page. If the traffic reaches Nginx, the program decides how to handle it based on its configuration, including the domain name and the path in the address.
Nginx can directly return static files, meaning resources saved in advance: HTML documents, CSS stylesheets, JavaScript scripts or images. However, it is not a content management system or a database. It does not create a shop dashboard or calculate the contents of a shopping cart itself — those are the application’s jobs.
Reverse proxy, HTTPS and other uses
Another important function of Nginx is acting as a reverse proxy, an intermediary that receives user requests on behalf of an application. The browser connects to Nginx, which forwards the request to the appropriate process or server and returns the response it receives. This means the application does not have to accept connections directly from the internet.
Typical uses include:
- Handling HTTPS. Nginx can use a TLS certificate to encrypt the connection to the browser. The connection between Nginx and the application requires separate configuration and does not automatically become encrypted.
- Load balancing. Nginx distributes requests among several instances of an application. How useful this is also depends on whether the application can run across multiple instances.
- Caching. Nginx can store an application’s response and reuse it instead of involving the application every time. This requires rules that prevent private content from being shared with other users.
- Redirects. It can direct visitors from HTTP to HTTPS or from an old address to a new one, if the administrator configures it to do so.
Nginx uses an event-driven architecture: a worker process can handle many connections by responding when data is ready to be read or written. This helps it handle concurrent traffic efficiently, but it does not mean that simply installing the program will speed up every website. Slow database queries can still delay responses.
Example: a shop and an application behind Nginx
Imagine a shop where Nginx serves the domain sklep.example. A request for a product photo may be handled by reading a file from disk. A request for the shopping cart, on the other hand, goes to the application, which checks the user’s session, retrieves data and prepares a response.
For WordPress, PHP code is usually executed by PHP-FPM, a separate program that manages PHP processes. Nginx forwards the relevant requests to it using the FastCGI protocol. For an application written in Node.js or Python, it can forward traffic over HTTP to the application’s server running on a local port.
This separation helps diagnose problems. If images are displayed but the shopping cart returns an error, Nginx may be working correctly while the application is failing. A 502 Bad Gateway error often indicates a problem obtaining a valid response from the service behind the proxy; its cause should be determined from the logs, which record the activity of Nginx and the application.
You should not indiscriminately enable caching for the entire shop. The shopping cart, customer dashboard and responses containing personal data need appropriate exclusions from caching or precise isolation rules.
Nginx or Apache — what matters when choosing?
Apache HTTP Server is another popular HTTP server. Both solutions can serve websites and act as intermediaries in communication with applications. The choice does not come down to a rule that “Nginx is fast, Apache is slow”: the type of traffic, configuration, application and administrator’s experience all matter.
One practical difference concerns .htaccess files, which in Apache can contain local rules, such as redirects. Nginx does not read them. When migrating a website, you therefore need to move the necessary rules into the Nginx configuration, rather than simply copying the website files.
Nginx and Apache can also work together: the former receives traffic, while the latter handles some of the requests. That is why the statement “the hosting uses Nginx” alone does not describe the entire setup or guarantee a particular level of performance.
Do you need to configure Nginx yourself?
On shared or managed hosting, ask the provider who is responsible for HTTPS, redirects, caching and the rules required by the application. You may be able to configure all the necessary settings in the control panel without access to the server configuration.
On your own VPS, or virtual private server, your responsibilities usually include installation, updates, certificates and troubleshooting. Before changing the configuration, keep a working copy of it. The nginx -t command checks the syntax and the availability of the specified files; however, it does not confirm that the application works correctly or that the rules are secure.
After a successful test, reload the configuration, then check the website, login, redirects and error logs. Confirm the exact file paths and service management commands in the documentation for Nginx and the operating system distribution you use — they depend on how it was installed.
See also: What is 2FA?
