LinuxCommandLibrary

nginx

Serve web content and reverse proxy

TLDR

Start server with the default configuration file

$ nginx
copy

Start server with a custom configuration file
$ nginx -c [configuration_file]
copy

Start server with a prefix for all relative paths in the configuration file
$ nginx -c [configuration_file] -p [prefix/for/relative/paths]
copy

Test the configuration without affecting the running server
$ nginx -t
copy

Reload the configuration by sending a signal with no downtime
$ nginx -s reload
copy

SYNOPSIS

nginx [-h] [-v] [-V] [-t] [-q] [-s signal] [-p prefix] [-c filename] [-g directives]

Examples:
nginx
Starts the Nginx server.

nginx -s reload
Reloads the Nginx configuration gracefully.

nginx -t
Tests the Nginx configuration file for syntax errors.

PARAMETERS

-h
    Displays help message and exits.

-v
    Shows Nginx version only and exits.

-V
    Displays Nginx version, compiler version, and configure arguments used during compilation.

-t
    Tests the configuration file for syntax correctness and validity without starting the server. Nginx will parse the configuration file and report any errors.

-q
    Suppresses non-error messages during configuration test (used with -t).

-s signal
    Sends a signal to the master process. Common signals include stop (fast shutdown), quit (graceful shutdown), reload (reload configuration), and reopen (reopen log files).

-p prefix
    Sets the prefix path, which is the installation directory. This affects where Nginx looks for configuration files, modules, and other resources.

-c filename
    Specifies an alternative configuration file to use instead of the default.

-g directives
    Sets global directives from the command line. These directives are processed before the main configuration file.

DESCRIPTION

Nginx (pronounced "engine-x") is a free, open-source, high-performance HTTP server, reverse proxy, and mail proxy server. It's renowned for its high concurrency, excellent performance, and low memory usage. Nginx excels at serving static content, handling a large number of concurrent connections, and improving the reliability and speed of web applications. Its event-driven architecture allows it to efficiently manage thousands of concurrent connections, making it a popular choice for high-traffic websites and complex distributed systems.

CAVEATS

Running nginx requires root privileges to bind to privileged ports (like 80 or 443), though worker processes typically drop privileges to a non-root user. The configuration file syntax is extremely strict; even minor errors can prevent Nginx from starting or reloading. Always test configurations with nginx -t before reloading in production. Debugging issues often heavily relies on detailed log files.

CONFIGURATION FILES

Nginx relies on a highly structured, declarative configuration file, typically found at /etc/nginx/nginx.conf or within an installation prefix. This file is organized into various contexts (e.g., main, events, http, server, location, upstream), allowing for fine-grained control over server behavior, virtual hosts, and request processing. It supports inclusion of multiple files for modularity.

SIGNALS AND PROCESS MANAGEMENT

The nginx master process responds to several signals for management without restarting the server. These include stop or quit for shutdown, reload for applying configuration changes, and reopen for rotating log files. Nginx operates with a master process and multiple worker processes; the master manages the workers, which handle client requests efficiently.

HISTORY

Nginx was originally developed by Igor Sysoev and first publicly released in 2004. Its primary motivation was to address the C10k problem – efficiently handling 10,000 or more concurrent connections – particularly for the high-traffic Rambler.ru website. Its innovative event-driven, asynchronous architecture provided a significant performance advantage over traditional process-per-connection servers, especially under heavy load. Nginx rapidly gained traction, becoming a dominant choice for high-traffic websites, reverse proxying, and load balancing globally. Nginx, Inc. was founded in 2011 for commercial offerings and was later acquired by F5 Networks in 2019.

SEE ALSO

apache2(8) or httpd(8)Alternative web servers., systemctl(1) or service(8)Tools for managing Nginx as a system service., curl(1), wget(1)Commands to test web server responses., netstat(8), ss(8)Utilities for network connection diagnostics.

Copied to clipboard