Skip to main content

Nginx from Zero: Config Files to HTTPS Setup

A beginner-friendly guide to understanding Nginx configuration files, core blocks, directives, and securing your server with HTTPS.

AI-written
Inewgen
28 Jul 2026Source: Dev.to4 min read (0 views)Last updated 29 Aug 2026
Share
Nginx from Zero: Config Files to HTTPS Setup

Stock photo for illustration only, not from the actual event

Font size
  • Nginx reads the main nginx.conf file directly while other files must be explicitly included.
  • Running Nginx under the dedicated www-data account provides better security and easier permissions.
  • Server blocks and directives control domain handling, static files, and logging paths.
  • HTTPS secures web traffic by encrypting data through modern TLS connections.

Approaching Nginx as a complete beginner might seem intimidating, but understanding its core configuration structure makes it much simpler. An Nginx folder can range from having just a single nginx.conf file to several other directories and files. Nginx reads the nginx.conf file directly, and any other file must be explicitly included or referenced from there.

A common question is why developers avoid using the ubuntu user for Nginx. The ubuntu user is your login account which owns your shell, PM2 processes, and Node.js applications. Nginx should run under a dedicated service account like www-data because it has fewer privileges for better security, serves as the standard on Ubuntu, and makes permission management much easier.

Regarding performance, the directive worker_processes auto tells Nginx to create one worker per CPU core of the host machine. While a specific number can be defined, it is safest for Nginx to adapt to the host machine automatically. The worker processes perform the actual work of serving requests, while the master process manages them.

nginx architecture diagram server workers

Stock photo for illustration only, not from the actual event

The events{} block defines how workers handle connections, configured via worker_connections 1024, which represents the maximum number of connections a worker can handle simultaneously. This means if we have 4 workers and 1024 worker connections, the workers can handle roughly 4096 simultaneous connections in total.

Never miss the latest news?

Subscribe to get news summaries by email - not often enough to be annoying.

โฆษณา

The http{} block is used to define everything related to HTTP and HTTPS configuration. Inside it, we find server blocks containing settings for specific websites or applications, featuring essential directives such as:

  • server_name: Specifies which hostnames this server block should respond to, such as your domain name or localhost.
  • root /var/www/html;: The directory where Nginx looks for static files, checking /var/www/html/about.html when a request for GET /about.html arrives.
  • index index.html index.htm;: Defines the default landing pages Nginx serves when visiting a domain.
  • access_log and error_log: Specifies where access and error logs are saved, typically within /var/log/nginx/.

Structuring Nginx configuration files cleanly is a best practice for system administration. By breaking down large configurations into modular files—such as moving server blocks into separate configuration files and referencing them inside the main file—developers can maintain readability and streamline troubleshooting in growing web applications.

When transmitting data over the web, standard HTTP sends all details including sensitive credentials in plain text. This information can easily be intercepted by internet service providers, malicious actors on public Wi-Fi, or hackers because HTTP lacks encryption, authentication, or integrity checks.

The letter 'S' in HTTPS stands for secure, meaning transmitted information is encrypted, authenticated, and protected against tampering through an encrypted TLS connection. While SSL was the original encryption protocol featuring handshakes, it is now obsolete and has been completely replaced by TLS (Transport Layer Security). Although people still commonly say 'SSL Certificate', modern certificates obtained from authorities like Let's Encrypt or DigiCert are technically TLS certificates.

Source: Dev.to

Comments

Leave a Comment
0/2000

Found something wrong in this article? Report an issue with this article