RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>Common Nginx Errors and How to Fix Them (400 to 504)
VPS Hosting

Common Nginx Errors and How to Fix Them (400 to 504)

Alex Vance
Alex Vance
Published Oct 11, 2026· Updated Nov 13, 2026•✓ Verified Expert Reviewed•3 min read
Common Nginx Errors and How to Fix Them (400 to 504) guide cover

Key Takeaways

  • ✓Two commands find almost every Nginx problem: nginx -t and the error log.
  • ✓A table of HTTP errors 400 to 504 with the cause and fix for each.
  • ✓Startup errors: port 80 in use, unknown directive, nginx.service not found.
  • ✓How to replace the default Nginx error page with your own.

Table of Contents

  • •Common Nginx Errors and How to Fix Them (400 to 504)
  • •Two Commands That Find Most Problems
  • •Nginx HTTP Errors at a Glance
  • •Nginx Startup and Config Errors
  • •bind() to 0.0.0.0:80 failed (98: Address already in use)
  • •unknown directive "..."
  • •could not build server_names_hash
  • •Failed to restart nginx.service: Unit nginx.service not found
  • •Reloading without downtime
  • •How to Set a Custom Nginx Error Page
  • •Frequently Asked Questions
  • •Rather Not Debug Nginx at 2 AM?

Common Nginx Errors and How to Fix Them (400 to 504)

Nginx errors fall into two groups: HTTP status codes that visitors see (403, 404, 502 and so on), and startup or config errors that stop Nginx from starting or reloading. This page covers both and links to a full guide for the most common ones.

For errors that are not specific to Nginx, see our general guides: 502 Bad Gateway, 403 Forbidden, 404 Not Found, ERR_CONNECTION_REFUSED and DNS_PROBE_FINISHED_NXDOMAIN.

Two Commands That Find Most Problems

# Check the configuration for syntax errors
sudo nginx -t

# Watch errors live while you reload the page
sudo tail -f /var/log/nginx/error.log

Access logs are in /var/log/nginx/access.log. If a site defines its own error_log, look there instead. On Docker, Nginx writes to the container output, so use docker logs.

Nginx HTTP Errors at a Glance

CodeMeaningMost common causeFix
400 Bad RequestMalformed requestCookie or header too large; plain HTTP sent to the HTTPS portClear cookies; raise large_client_header_buffers 4 16k;
403 ForbiddenNot allowed to serveMissing index file, permissions, deny rule, SELinuxFull 403 guide
404 Not FoundPath not mappedroot vs alias, missing try_files, wrong server blockFull 404 guide
413 Request Entity Too LargeUpload too bigDefault client_max_body_size is 1 MBSet client_max_body_size 64M; (and PHP upload_max_filesize)
499 Client Closed RequestVisitor gave upSlow backend; client timed out firstSpeed up the upstream
500 Internal Server ErrorError while handlingApp crash, or a rewrite loop in NginxCheck app logs; look for "rewrite or internal redirection cycle"
502 Bad GatewayUpstream failedPHP-FPM/Node/container down or wrong addressFull 502 guide
503 Service UnavailableTemporarily refusinglimit_req/limit_conn limits or maintenance modeReview rate limits; disable maintenance
504 Gateway TimeoutUpstream too slowLong queries or scriptsFix the slow code; raise proxy_read_timeout / fastcgi_read_timeout

Nginx Startup and Config Errors

bind() to 0.0.0.0:80 failed (98: Address already in use)

Another program (often Apache, or a second Nginx) holds the port. Find it and stop it:

sudo ss -tlpn | grep -E ":80 |:443 "
sudo systemctl disable --now apache2

unknown directive "..."

A typo, a missing semicolon on the line above, or a directive from a module that is not installed (for example brotli or more_set_headers). nginx -t prints the file and line number.

could not build server_names_hash

Too many or very long domain names. Add server_names_hash_bucket_size 128; inside the http block.

Failed to restart nginx.service: Unit nginx.service not found

systemd does not know an Nginx service on this machine. Either Nginx is not installed (sudo apt install nginx or sudo dnf install nginx), it was installed another way (a Docker container, a control panel, or OpenResty with its own service name), or you are inside a container where systemd is not running. Check with systemctl list-unit-files | grep -i nginx and which nginx.

Reloading without downtime

Always test first, then reload rather than restart; a reload keeps serving traffic while the new config loads:

sudo nginx -t && sudo systemctl reload nginx

How to Set a Custom Nginx Error Page

Replace the plain default page with your own branded one:

server {
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /404.html { root /var/www/errors; internal; }
    location = /50x.html { root /var/www/errors; internal; }
}

internal stops visitors from opening the error page directly. For errors returned by a proxied app, add proxy_intercept_errors on; so Nginx shows your page instead of the app's.

Frequently Asked Questions

Where is the Nginx error log?
Usually /var/log/nginx/error.log. Run sudo nginx -T | grep error_log to see every log path in your config.

How do I check if my Nginx config is valid?
Run sudo nginx -t. It reports "syntax is ok" and "test is successful", or the exact file and line of the error.

What is the difference between nginx reload and restart?
Reload applies new config gracefully without dropping connections. Restart stops and starts the process, briefly interrupting traffic.

How do I hide the Nginx version on error pages?
Add server_tokens off; to the http block. The page will say only nginx.

Rather Not Debug Nginx at 2 AM?

Every error in this guide is something a managed host fixes for you. RackUp IT managed hosting runs a tuned Nginx, PHP and caching stack with monitoring, backups and SSL handled, so you can spend your time on the site instead of the server.

← Previous Article404 Not Found in Nginx: Why It Happens and How to Fix ItNext Article →How to Open Ports on a VPS: UFW, iptables & firewalld
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • Common Nginx Errors and How to Fix Them (400 to 504)
  • Two Commands That Find Most Problems
  • Nginx HTTP Errors at a Glance
  • Nginx Startup and Config Errors
  • bind() to 0.0.0.0:80 failed (98: Address already in use)
  • unknown directive "..."
  • could not build server_names_hash
  • Failed to restart nginx.service: Unit nginx.service not found
  • Reloading without downtime
  • How to Set a Custom Nginx Error Page
  • Frequently Asked Questions
  • Rather Not Debug Nginx at 2 AM?

Categories

  • VPS Hosting
  • DevOps & Tutorials
  • WordPress Hosting
  • Cloud Hosting
  • Server Stack
  • Networking & Security
  • Web Hosting / Managed Cloud
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Vultr Alternatives in 2026: VPS Hosting for Developers Compared
  • Docker Port Mapping Explained: -p, EXPOSE and Compose ports
  • Bluehost Alternatives (2026): WordPress Hosting Without the Renewal Price Jump

Tags

NginxTroubleshootingError CodesVPS HostingLinux

Related Posts

Vultr alternatives coverVPS Hosting
Nov 27, 2026

Vultr Alternatives in 2026: VPS Hosting for Developers Compared

Vultr's Regular Performance prices compared with DigitalOcean, Linode, Hetzner and a fixed-plan VPS at the 8 GB size, plus when container hosting fits better.

Read Article →
What is a VPS? Virtual private servers explainedVPS Hosting
Nov 20, 2026

What Is a VPS? Virtual Private Servers Explained

A VPS (virtual private server) is a virtual machine with its own operating system, resources and root access. How it works, uses, and when you need one.

Read Article →
Linode alternatives coverVPS Hosting
Nov 19, 2026

Linode (Akamai) Alternatives in 2026: VPS Hosting Compared

Linode's shared CPU prices from Akamai's own API, compared with DigitalOcean, Vultr and a fixed-plan VPS, plus when container hosting makes more sense.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting
  • Managed WordPress VPS
  • Website Speed Test

Subscribe to our newsletter

We accept
  • bKash
  • Nagad
  • Rocket
  • Upay
  • CellFin
  • Meghna Pay
  • OK Wallet
  • Tap
  • mCash
  • DBBL Nexus
  • Visa
  • Mastercard
  • American Express
  • Crypto
Pay with Visa, Mastercard, American Express, DBBL Nexus, CellFin, Rocket, bKash, Tap, Meghna Pay, Nagad, mCash, Upay and OK Wallet. Verified by EPS

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service