Domain 10Linux & SREINTERMEDIATE

(Cape Town) Troubleshooting Nginx Failures: Resolving Syntax Errors and Systemd Resource Limits (EMFILE)

A comprehensive deep dive into troubleshooting Nginx service startup failures caused by configuration syntax errors and resolving secondary HTTP 500 EMFILE errors stemming from Systemd file descriptor resource limits (LimitNOFILE).

Domain: Domain 10: Linux Internals, SRE & Troubleshooting•Updated: 2026-11-09
#Nginx#Systemd#Linux#Troubleshooting#SRE#Resource-Limits#Networking

1. Introduction

In modern web infrastructure, reverse proxies and web servers like Nginx serve as critical gateways. When an Nginx instance fails to serve web traffic, the root cause can span multiple abstraction layers—from physical network routing and firewall rules down to kernel-level process restrictions and configuration syntax errors.

System Reliability Engineers (SREs) and Linux Systems Administrators must approach web server outages systematically. A common operational trap is assuming an outage stems from a single fault. In complex environments, fixing a primary failure condition can unmask underlying secondary misconfigurations.

This article documents a multi-tiered troubleshooting scenario involving an Nginx service managed by Systemd on a Linux host. We will explore how to diagnose service launch failures, parse Nginx syntax errors, inspect kernel process limits via the /proc filesystem, and adjust Systemd unit file resource boundaries (LimitNOFILE).


2. Problem Description and Environment

Scenario Background

The exercise (“Cape Town”: Borked Nginx) presents a scenario where an Nginx web server is installed and managed by Systemd. The server is failing to respond to local HTTP requests.

Technical Metrics & Constraints

  • Operating System: Ubuntu / Debian-based Linux environment (hostname: ip-10-1-13-7).
  • Service Manager: systemd.
  • Web Server: Nginx (version 1.18.0).
  • User Privileges: Administrative root access (sudo).
  • Expected Outcome: Executing curl -Is 127.0.0.1:80 | head -1 returns an HTTP/1.1 200 OK response header.
  • Initial Symptom: Executing curl -I 127.0.0.1:80 fails immediately with curl: (7) Failed to connect to localhost port 80: Connection refused.
admin@ip-10-1-13-7:/$ curl -I 127.0.0.1:80
curl: (7) Failed to connect to localhost port 80: Connection refused

3. Initial Investigation and Hypotheses

A Connection refused error at the transport layer (TCP) indicates that incoming SYN packets to 127.0.0.1:80 are actively rejected by the OS network stack because no listening socket is bound to that port, or a firewall rule is issuing an explicit RST (Reset) packet.

Initial Hypotheses Matrix

Hypothesis Plausibility Supporting Evidence Evidence Against Diagnostic Step
H1: Nginx service is stopped/inactive High curl returns Connection refused on port 80. None currently. Run systemctl status nginx.
H2: Nginx failed to start due to configuration syntax error High Common in fresh or modified web server deployments. None currently. Run nginx -t or check systemd logs.
H3: Nginx is bound to a non-standard port or IP Medium Connection refused on 127.0.0.1:80. System default configuration usually binds to :80. Inspect active listening ports via ss -tulpn.
H4: Host firewall (iptables/nftables/ufw) is blocking port 80 Low Local loopback traffic is rarely blocked by default. Local socket behavior usually rejects via RST. Inspect firewall rules via iptables -L.

4. Troubleshooting Process

Step 1: Inspect Systemd Service Status

Objective

Determine whether the Nginx service unit is active, inactive, or in a failed state under Systemd management.

Command

sudo systemctl status nginx --no-pager

Command Explanation

  • systemctl status: Interrogates the Systemd daemon for the state of a unit (nginx.service).
  • --no-pager: Pipes output directly to standard output without spawning a terminal pager like less.

Output and Analysis

● nginx.service - The NGINX HTTP and reverse proxy server
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2026-11-09 04:29:37 UTC; 39s ago
    Process: 569 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
        CPU: 26ms

Nov 09 04:29:37 ip-10-1-13-7 systemd[1]: Starting The NGINX HTTP and reverse proxy server...
Nov 09 04:29:37 ip-10-1-13-7 nginx[569]: nginx: [emerg] unexpected ";" in /etc/nginx/sites-enab…ault:1
Nov 09 04:29:37 ip-10-1-13-7 nginx[569]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 09 04:29:37 ip-10-1-13-7 systemd[1]: nginx.service: Control process exited, code=exited, st…AILURE
Nov 09 04:29:37 ip-10-1-13-7 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 09 04:29:37 ip-10-1-13-7 systemd[1]: Failed to start The NGINX HTTP and reverse proxy server.

Key Findings:

  1. The service state is failed.
  2. Systemd executed a pre-start check directive: ExecStartPre=/usr/sbin/nginx -t.
  3. The configuration check exited with status=1/FAILURE.
  4. Log output highlights an error: unexpected ";" in /etc/nginx/sites-enabled/default:1.

Decision

Confirm hypothesis H2. The service refused to start because of a configuration syntax error on line 1 of /etc/nginx/sites-enabled/default.


Step 2: Validate Nginx Configuration Syntax Directly

Objective

Isolate and confirm the exact parsing error using Nginx’s native configuration testing utility.

Command

sudo nginx -t

Command Explanation

  • nginx -t: Parses all configuration files referenced starting from /etc/nginx/nginx.conf, checks for valid syntax, tests file accessibility, and returns exit code 0 on success or 1 on failure.

Output and Analysis

nginx: [emerg] unexpected ";" in /etc/nginx/sites-enabled/default:1
nginx: configuration file /etc/nginx/nginx.conf test failed

Decision

Inspect the top lines of /etc/nginx/sites-enabled/default to identify the syntax anomaly.


Step 3: Inspect the Affected Configuration File

Objective

Examine line 1 of /etc/nginx/sites-enabled/default to understand the illegal syntax.

Command

head -n 5 /etc/nginx/sites-enabled/default

Command Explanation

  • head -n 5: Prints the first 5 lines of the target file.

Output and Analysis

;
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/

Key Findings:

Line 1 contains a standalone semicolon ;. In Nginx configuration files, semicolons are strictly used as statement terminators for directives (e.g., listen 80;). A leading semicolon outside any context or directive is invalid syntax.


Step 4: Remediate the Syntax Error & Attempt Service Start

Objective

Remove the invalid character from line 1 of the configuration file, verify syntax validity, and start the Nginx service.

Commands Executed

# 1. Remove line 1 from the underlying configuration file in sites-available
sudo sed -i '1d' /etc/nginx/sites-available/default

# 2. Re-test Nginx configuration syntax
sudo nginx -t

# 3. Start Nginx systemd service
sudo systemctl start nginx

# 4. Check active service state
sudo systemctl is-active nginx.service

Command Explanations

  • sed -i '1d': Stream editor configured for in-place editing (-i). 1d instructs sed to delete line 1.
  • systemctl start nginx: Triggers Systemd to execute ExecStartPre followed by ExecStart.
  • systemctl is-active: Returns the operational status of the service unit (active vs inactive/failed).

Output and Analysis

admin@ip-10-1-13-7:/$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

admin@ip-10-1-13-7:/$ sudo systemctl start nginx
admin@ip-10-1-13-7:/$ sudo systemctl is-active nginx.service 
active

Decision

Nginx is now running and bound to port 80. Proceed to perform the target HTTP test to verify resolution.


Step 5: Perform Initial HTTP Verification & Identify Secondary Error

Objective

Verify HTTP connectivity using curl.

Command

curl -Is 127.0.0.1:80 | head -5

Command Explanation

  • curl -Is: Sends an HTTP HEAD request (-I) in silent mode (-s, suppressing progress bars).
  • head -5: Limits output to the first 5 HTTP header lines.

Output and Analysis

HTTP/1.1 500 Internal Server Error
Server: nginx/1.18.0
Date: Mon, 09 Nov 2026 04:33:31 GMT
Content-Type: text/html
Content-Length: 177

Key Findings:

The TCP layer connection succeeded (the previous Connection refused error is resolved). However, Nginx responded with an HTTP 500 Internal Server Error.

Decision

A 500 status code is an application-layer failure. Nginx accepted the incoming TCP connection but encountered an unrecoverable system call failure while attempting to process the request. Inspect /var/log/nginx/error.log to determine the cause.


Step 6: Inspect Nginx Error Logs for Application Failure

Objective

Analyze recent log entries written by Nginx worker processes.

Command

sudo tail -n 20 /var/log/nginx/error.log

Output and Analysis

2026/11/09 04:33:04 [alert] 944#944: socketpair() failed while spawning "worker process" (24: Too many open files)
2026/11/09 04:33:04 [emerg] 945#945: eventfd() failed (24: Too many open files)
2026/11/09 04:33:04 [alert] 945#945: socketpair() failed (24: Too many open files)
2026/11/09 04:33:31 [crit] 945#945: *1 open() "/var/www/html/index.nginx-debian.html" failed (24: Too many open files), client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "127.0.0.1"

Key Findings:

The error log reveals multiple critical failures:

  1. socketpair() failed (24: Too many open files)
  2. eventfd() failed (24: Too many open files)
  3. open() "/var/www/html/index.nginx-debian.html" failed (24: Too many open files)

Diagnostic Conclusion:

In Linux kernel error tables, Errno 24 corresponds to EMFILE (“Too many open files”). The Nginx process has reached its maximum allocated limit for open file descriptors (FDs).


Step 7: Investigate Process Resource Limits (RLIMIT_NOFILE)

Objective

Identify where the file descriptor limit is enforced: system-wide, within the Nginx configuration, or via Systemd unit directives.

Commands Executed

# 1. Inspect Systemd Unit configuration file
sudo systemctl cat nginx

# 2. Inspect active limits for running Nginx master/worker process
cat /proc/$(pgrep -n nginx)/limits | grep "Max open files"

# 3. Inspect kernel global file descriptor allocation
cat /proc/sys/fs/file-nr

Command Explanations

  • systemctl cat nginx: Displays the full content of the service unit file /etc/systemd/system/nginx.service and any active drop-in configurations.
  • /proc/[PID]/limits: Virtual kernel file listing all soft and hard resource limits (RLIMIT_*) enforced on a specific running process ID.
  • pgrep -n nginx: Returns the Process ID (PID) of the newest (-n) running nginx process.
  • /proc/sys/fs/file-nr: Kernel interface returning global system file descriptor statistics (Allocated FDs, Unused FDs, Maximum system FDs).

Output and Analysis

admin@ip-10-1-13-7:/$ sudo systemctl cat nginx
# /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
LimitNOFILE=10

[Install]
WantedBy=multi-user.target

admin@ip-10-1-13-7:/$ cat /proc/$(pgrep -n nginx)/limits | grep "Max open files"
Max open files            10                   10                   files     

admin@ip-10-1-13-7:/$ cat /proc/sys/fs/file-nr
640     0       9223372036854775807

Key Findings:

  1. Systemd Unit Restriction: /etc/systemd/system/nginx.service contains LimitNOFILE=10.
  2. Kernel Enforcement: /proc/[PID]/limits shows Max open files set to 10 (Soft) and 10 (Hard).
  3. Global System Limits: /proc/sys/fs/file-nr shows 9223372036854775807 available system-wide. The constraint is isolated to the Nginx process via Systemd’s CGroup resource settings.

Decision

Modify /etc/systemd/system/nginx.service to raise LimitNOFILE to a standard production baseline (e.g., 65535), reload systemd, and restart Nginx.


Step 8: Remediate Resource Limit, Reload Systemd, and Restart Service

Objective

Update the LimitNOFILE setting in the unit file and reload the service daemon.

Commands Executed

# 1. Edit /etc/systemd/system/nginx.service to change LimitNOFILE=10 to LimitNOFILE=65535
sudo nano /etc/systemd/system/nginx.service

# 2. Reload Systemd manager configuration
sudo systemctl daemon-reload

# 3. Restart Nginx to spawn processes with updated limits
sudo systemctl restart nginx

Command Explanations

  • systemctl daemon-reload: Forces Systemd to scan /etc/systemd/system/ and /lib/systemd/system/ for modified unit files, updating its internal execution graphs without restarting unrelated services.
  • systemctl restart nginx: Stops and starts the Nginx service, causing the new process to inherit updated RLIMIT_NOFILE values from Systemd.

5. Root Cause Analysis

The outage was caused by two distinct faults acting at different operational layers:

[ Incoming HTTP Request: curl 127.0.0.1:80 ]
                  │
                  ▼
   ┌──────────────────────────────┐
   │  Layer 4: TCP Socket Check   │
   └──────────────┬───────────────┘
                  │
        [ Service Inactive ] ──> Cause 1: Syntax error ";" in default:1
                  │             (ExecStartPre failed, Nginx stopped)
                  ▼
   ┌──────────────────────────────┐
   │  Layer 7: HTTP Processing    │
   └──────────────┬───────────────┘
                  │
        [ HTTP 500 Error ]   ──> Cause 2: LimitNOFILE=10 in unit file
                                (Process ran out of FDs: EMFILE Errno 24)

Fault 1: Startup Blocker (Syntax Error)

Nginx utilizes a systemd unit directive ExecStartPre=/usr/sbin/nginx -t to validate configuration syntax prior to launching the daemon. Line 1 of /etc/nginx/sites-enabled/default contained a rogue semicolon ;. This caused nginx -t to exit with status 1, causing Systemd to fail the startup sequence and leave TCP port 80 unassociated with any listening process (Connection refused).

Fault 2: Application Blocker (EMFILE / LimitNOFILE Exhaustion)

Once Fault 1 was cleared, Nginx started, but encountered LimitNOFILE=10 in /etc/systemd/system/nginx.service.

In Linux, file descriptors are integer handles assigned by the kernel when a process opens files, network sockets, inter-process communication channels, or event multiplexers. An active Nginx process consumes:

  • 3 FDs for Standard I/O streams (stdin, stdout, stderr).
  • 1 FD for inter-process socketpair() per worker process.
  • 1 FD for epoll() / eventfd() kernel event queues.
  • 2 FDs for network sockets listening on IPv4 (0.0.0.0:80) and IPv6 ([::]:80).
  • 2 FDs for access and error log files (/var/log/nginx/access.log, /var/log/nginx/error.log).

By the time Nginx completes initialization, all 10 file descriptor slots are consumed. When an incoming request arrives and Nginx attempts an open() system call for /var/www/html/index.nginx-debian.html, the kernel returns error EMFILE (Errno 24: Too many open files). Unable to read the requested index file from disk, Nginx yields an HTTP 500 Internal Server Error.


6. Solution and Remediation

Configuration Changes Summary

1. Configuration Syntax Fix

  • Target File: /etc/nginx/sites-available/default (linked to /etc/nginx/sites-enabled/default)
  • Modification: Line 1 containing ; was removed.
# BEFORE (/etc/nginx/sites-available/default)
;
##
# You should look at the following URL's...

# AFTER (/etc/nginx/sites-available/default)
##
# You should look at the following URL's...

2. Systemd Resource Limit Fix

  • Target File: /etc/systemd/system/nginx.service
  • Modification: Changed LimitNOFILE=10 to LimitNOFILE=65535.
# BEFORE (/etc/systemd/system/nginx.service)
[Service]
...
LimitNOFILE=10

# AFTER (/etc/systemd/system/nginx.service)
[Service]
...
LimitNOFILE=65535

7. Verification and Validation

The resolution was validated using the following sequence:

1. Verify Active Resource Limits on Running Process

cat /proc/$(pgrep -n nginx)/limits | grep "Max open files"

Result: Output confirms the soft and hard limits are raised to 65535:

Max open files            65535                65535                files     

2. Perform HTTP Service Header Verification

curl -Is 127.0.0.1:80 | head -1

Result: Target test returns HTTP/1.1 200 OK:

HTTP/1.1 200 OK

3. Verify Error Logs

sudo tail -n 5 /var/log/nginx/error.log

Result: No new EMFILE or open() error entries logged following request handling.


8. Alternative Troubleshooting Approaches

When investigating web server issues or resource limits, SREs can leverage several alternative diagnostic tools:

Diagnostic Tools Comparison

Tool / Approach Command Example Use Case Primary Advantage
lsof sudo lsof -p <PID> Lists all open file descriptors for a process. Directly maps open FDs to specific sockets, logs, and files on disk.
strace sudo strace -e open,openat,socketpair -p <PID> Traces system calls executed by a process in real-time. Instantly captures exact syscall failures (e.g., open(...) = -1 EMFILE).
ss sudo ss -tulpn Inspects socket state and network bindings. Faster replacement for netstat; reveals listening PIDs on port 80.
journalctl sudo journalctl -u nginx -e Views Systemd daemon logs. Captures unit startup failures and stdout/stderr from ExecStartPre.
/proc/[PID]/fd sudo ls -l /proc/<PID>/fd/ Inspects open file links dynamically. Direct kernel view of allocated file descriptor symlinks.

Example Alternative Commands

Inspecting Open File Descriptors via lsof

sudo lsof -p $(pgrep -n nginx)

Output Insights: Displays a line-by-line list of every open handle allocated by Nginx, including file types (REG, DIR, IPv4), inode numbers, and active paths.

Tracing System Calls via strace

sudo strace -f -e trace=open,openat,socket -p $(pgrep -n nginx)

Output Insights: Directly exposes failing system calls:

openat(AT_FDCWD, "/var/www/html/index.nginx-debian.html", O_RDONLY) = -1 EMFILE (Too many open files)

9. Linux Command Deep Dive

Command: systemctl

Purpose

Central utility for controlling the Systemd init system and service manager.

Syntax

systemctl [OPTIONS] COMMAND [UNIT...]

Useful Troubleshooting Options

Command Variant Purpose
systemctl status <unit> Shows operational state, CGroup PID tree, and recent log entries.
systemctl cat <unit> Displays the unit file source code and active overrides on disk.
systemctl daemon-reload Re-reads all unit files and updates systemd internal dependencies.
systemctl show <unit> -p LimitNOFILE Queries specific unit parameters evaluated by Systemd.
systemctl list-units --failed Lists all units across the system currently in a failed state.

Command: nginx

Purpose

High-performance HTTP server, reverse proxy, and IMAP/POP3 proxy server executable.

Syntax

nginx [OPTIONS]

Useful Troubleshooting Options

Command Variant Purpose
nginx -t Tests configuration syntax and verifies included files without reloading.
nginx -T Tests configuration and dumps the consolidated config to stdout.
nginx -s reload Sends a reload signal to the master process for zero-downtime config updates.
nginx -v / nginx -V Displays Nginx version, compiler settings, and loaded modules.

Command: sed

Purpose

Non-interactive stream editor for filtering and transforming text streams or files.

Syntax

sed [OPTIONS] 'SCRIPT' FILENAME

Useful Options

Command Variant Purpose
sed -i '1d' <file> In-place deletion (-i) of line 1 (1d).
sed -i 's/foo/bar/g' <file> Replaces all occurrences of string foo with bar in place.
sed -n '10,20p' <file> Prints only lines 10 through 20 from a target file.

10. Underlying Linux Concepts and Architecture

1. Kernel Resource Limits (RLIMIT_NOFILE)

In Linux, resource limits (rlimit) restrict process resource consumption to prevent single-application runaway bugs from compromising host stability:

  • Soft Limit: The value enforced by the kernel for the process. A process can raise its soft limit up to the hard limit ceiling using setrlimit().
  • Hard Limit: The maximum cap for the soft limit. Only privileged processes (CAP_SYS_RESOURCE or root) can raise the hard limit.

When a process attempts an operation (open(), accept(), pipe(), socket()) requiring a new file descriptor while current_fds >= soft_limit, the system call returns -1 with errno set to EMFILE (24).

2. Systemd Resource Control & CGroups

Traditional limit definitions placed in /etc/security/limits.conf apply only to user login sessions managed by pam_limits.so. They do not apply to background daemons managed by Systemd.

Systemd sets process limits directly before spawning the process binary using Linux control groups (CGroups) and prlimit() kernel calls. Unit directives format:

[Service]
LimitNOFILE=65535
LimitNPROC=4096
LimitMEMLOCK=infinity

3. Nginx Configuration Hierarchy on Debian/Ubuntu

On Debian/Ubuntu Linux distributions, Nginx uses a split configuration pattern to manage multi-tenant virtual hosts:

/etc/nginx/
├── nginx.conf                 <-- Main configuration file (defines http {} block)
├── conf.d/                    <-- Global HTTP context configs (*.conf)
├── sites-available/           <-- Storage area for available vhost configs
└── sites-enabled/             <-- Symlinks to sites-available/ to enable vhosts

Inside nginx.conf, site inclusions are loaded dynamically:

http {
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

If a file in sites-enabled/ contains invalid syntax, the entire Nginx process fails syntax validation during nginx -t or startup.


11. Real-World Sysadmin and SRE Applications

Production Best Practices

1. Use Systemd Drop-In Override Files

Editing system-provided unit files directly in /etc/systemd/system/ or /lib/systemd/system/ creates maintenance debt during package upgrades. The SRE standard for modifying service parameters is using Systemd Drop-In Overrides:

# Create drop-in configuration directory
sudo mkdir -p /etc/systemd/system/nginx.service.d

# Create custom override file
sudo bash -c 'cat <<EOF > /etc/systemd/system/nginx.service.d/override.conf
[Service]
LimitNOFILE=65535
EOF'

# Reload systemd daemon
sudo systemctl daemon-reload

2. CI/CD Pipeline Validation

To prevent invalid configurations from reaching production, include automated validation steps in deployment pipelines prior to service reload:

# Example CI deployment step
nginx -t -c /path/to/repo/nginx.conf || { echo "Nginx syntax check failed!"; exit 1; }

3. Monitoring File Descriptor Consumption

Set up Prometheus alerts using node_exporter to track process file descriptor usage before reaching kernel ceilings:

# Prometheus Alerting Rule Example
- alert: ProcessNearFDLimit
  expr: (process_open_fds / process_max_fds) > 0.80
  for: 5m
  labels:
    severity: warning
  annotations:
    summary: "Process {{ $labels.process }} is using {{ $value | humanizePercentage }} of open FD limits."

12. Further Learning and Experiments

To deepen your understanding of Linux process limits and Systemd behaviors, try the following exercises in a safe sandbox VM:

Hands-on Lab: Reproducing FD Exhaustion

  1. Create a Test Service Unit: Create a dummy script /usr/local/bin/fd_test.sh that opens multiple files in a loop.
  2. Apply Systemd Restriction: Define a systemd service /etc/systemd/system/fdtest.service with LimitNOFILE=5.
  3. Observe Error Behavior: Start the service, execute journalctl -u fdtest -f, and observe how the kernel returns EMFILE when the 6th file handle is requested.
  4. Inspect /proc Limits: Run cat /proc/$(pgrep -f fd_test.sh)/limits to verify active kernel enforcement.

13. Key Takeaways

  1. Transport vs Application Errors: Connection refused points to a stopped service or missing socket listener. HTTP 500 indicates a running service failing to handle an application request internally.
  2. Always Check Logs First: Running sudo tail -n 20 /var/log/nginx/error.log immediately turns an ambiguous HTTP 500 into an actionable root cause (EMFILE: Too many open files).
  3. Systemd Resource Limits Override Shell Defaults: Systemd daemons bypass /etc/security/limits.conf. Adjust service limits using LimitNOFILE in the unit file or via drop-in overrides in /etc/systemd/system/<unit>.service.d/.
  4. Always Reload Systemd After Unit Edits: Modifying unit files requires executing systemctl daemon-reload before changes take effect during service restarts.

14. Quick Troubleshooting Reference / Runbook

                  Nginx Outage Diagnostics
                             │
            ┌────────────────┴────────────────┐
            ▼                                 ▼
   [ Connection Refused ]             [ HTTP 500 Error ]
            │                                 │
   1. Check service status:          1. Inspect Nginx error log:
      systemctl status nginx            tail -20 /var/log/nginx/error.log
            │                                 │
   2. Test config syntax:            2. Look for "Too many open files":
      sudo nginx -t                     Check /proc/$(pgrep -n nginx)/limits
            │                                 │
   3. Fix syntax error in:           3. Adjust LimitNOFILE in unit file:
      /etc/nginx/sites-enabled/         /etc/systemd/system/nginx.service
            │                                 │
   4. Start Nginx service:           4. Apply systemd changes:
      sudo systemctl start nginx        sudo systemctl daemon-reload
                                        sudo systemctl restart nginx

Quick Commands List

  • Check Service State: sudo systemctl status nginx
  • Validate Nginx Syntax: sudo nginx -t
  • View Error Log: sudo tail -f /var/log/nginx/error.log
  • Inspect Process Limits: cat /proc/$(pgrep -n nginx)/limits
  • Reload Systemd: sudo systemctl daemon-reload
  • Verify Header Status: curl -Is 127.0.0.1:80 | head -1