Glossary

Nginx

What is Nginx

Nginx is a lightweight, high-performance web server and reverse proxy server, known for its low memory usage and strong concurrency. It is widely used to deliver web content, terminate encrypted connections, and forward client requests to backend servers.

Unlike the traditional multi-process or multi-thread model, Nginx uses an event-driven, asynchronous, non-blocking I/O model. This allows it to keep resource consumption low and response speed high, even when handling a large number of concurrent connections. Its architecture consists of a master process and multiple worker processes: the master process reads and evaluates the configuration and manages the workers, while the worker processes handle the actual client requests.

How Nginx Works

On an AsterNOS routing device, Nginx is controlled through the device's own command line and a set of configuration files.

  • Server blocks: A server block defines a virtual host, which can distinguish different websites by domain name, IP address, and port. One http block can contain multiple server blocks. If SSL-encrypted access is used, the certificate and key file paths must be specified in the block as well.

  • Local content: A server block can serve resources stored on the device, such as files in the local eMMC partition. Removable USB drives or NVMe disks can be mounted and used the same way.

  • Reverse proxy: A server block can also forward client requests to a backend server. Requests can be split by URL path, so, for example, a path ending in /static/ is served from local storage while all other requests are proxied.

  • Core allocation: Nginx runs together with VPP (Vector Packet Processing) on the device's CPU cores. The core counts for each can be configured to balance packet forwarding and web service performance.

  • Configuration directories: Nginx files are stored under /etc/sonic/nginx/. The conf folder holds the running configuration, the configed folder holds the files read whenever nginx reload is executed, and the saved folder holds configurations saved with the write command. Files should be edited in configed, since changes to conf are overwritten at the next reload.

  • Applying changes: After any configuration change, such as updating a server file, changing global parameters, or adjusting the Nginx core count, nginx reload must be executed. To keep the configuration after a device restart, it must be saved with write.

Why Nginx is Beneficial

Running Nginx directly on the network device brings web delivery and proxying closer to the traffic:

  • High concurrency with low resource usage: The event-driven model handles many simultaneous connections efficiently.

  • Flexible request handling: URL-based rules let one service serve local files for some paths and proxy others to backend servers.

  • Secure access: SSL support allows encrypted access using certificates stored on the device.

  • Fewer extra devices: Web content delivery and reverse proxy functions can be provided by the same device that routes the traffic.

  • Tunable performance: Core allocation, connection limits, keepalive timeouts, and queue cache sizes can be adjusted to fit the workload.

At Asteraix

What We Can Do at Asteraix

AsterNOS supports Nginx on its routing and gateway platforms, allowing a device to provide web services and reverse proxy functions for the network it serves:

  • Global switch: Nginx is enabled and disabled system-wide with nginx enable and nginx stop.

  • Core allocation: cpu_core sets the number of cores used by Nginx and VPP. On the ET2500, which has 8 cores, the defaults are 6 for VPP and 1 for Nginx, and the recommended setting is 3 for each. The total must not exceed 8. Nginx core changes take effect after nginx reload, while VPP core changes require write followed by a device reload.

  • Global parameters: nginx keepalive_timeout sets the TCP connection keepalive timeout, and nginx worker_connections sets the maximum number of connections each worker process can open at the same time.

  • Loading files: nginx update {cert|server} loads certificate files and server configuration files onto the device.

  • Queue cache tuning: Queue cache sizes used by Nginx can be adjusted in the vcl.conf file under /etc/sonic/nginx/conf, and take effect after a device reload.

  • Monitoring: show nginx status shows whether Nginx is enabled and how many cores it uses, and show nginx config shows the global parameters and the loading status of configuration files.

  • Typical deployment: A company needs its egress device to provide Nginx services so that users can access resources on other partitions or reach backend servers through reverse proxy. The administrator enables Nginx, allocates cores, sets the keepalive timeout and worker connections, loads a server configuration file, reloads Nginx, and configures the Layer 3 interfaces so clients can reach the service.

sonic(config)# nginx start
sonic(config)# cpu_core vpp_num 3 nginx_num 3
sonic(config)# nginx keepalive_timeout 80
sonic(config)# nginx worker_connections 1500
sonic(config)# nginx update server /home/admin/nginx_test1.conf
sonic(config)# nginx reload