QR CookingNotes

CookingNotes

Your Personal Recipe Book

Get it on Google Play
QR FiNoteMe

FiNoteMe

Smart Finance Tracker

Get it on Google Play
linuxserver • If Nginx won’t start, your websites go down, and it can be stressful for beginners. This tutorial explains, step-by-step, why Nginx may fail to start, how to diagnose the issue, and how to fix it safely.

Nginx Won’t Start and How to Fix It (Beginner-Friendly Guide)

5 Min Read Verified Content

# Step 1 — Check Nginx Status


First, see the current status:

sudo systemctl status nginx

Look for:

  • Active: inactive (dead)

  • Failed to start messages

  • Errors at the bottom

Example output:

● nginx.service - A high performance web server Loaded: loaded (/lib/systemd/system/nginx.service; disabled) Active: failed (Result: exit-code)


## Step 2 — Test Nginx Configuration


A common reason Nginx won’t start is a syntax error in the configuration.

Run:

sudo nginx -t

You might see:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: configuration file /etc/nginx/nginx.conf test failed

Fix any errors reported here before proceeding.




## Step 3 — Check for Port Conflicts


Nginx usually uses ports 80 (HTTP) and 443 (HTTPS). If another process is using the port, Nginx won’t start.

Check which process uses port 80:

sudo lsof -i :80

Or:

sudo netstat -tulpn | grep :80

If you see Apache, another Nginx instance, or any process using the port:

  • Stop the conflicting service:

sudo systemctl stop apache2 sudo systemctl stop nginx # stop old instance if needed
  • Or change Nginx port in /etc/nginx/sites-available/default



## Step 4 — Check Logs for Errors


Nginx logs are in /var/log/nginx/.

Check error log:

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

Look for:

  • Missing files (e.g., certificate, HTML)

  • Syntax errors in virtual host configs

  • Permission issues




## Step 5 — Fix Permission Issues


Nginx may fail to start if it cannot read files.

Check ownership and permissions:

sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/html

For SSL certificates:

sudo chmod 600 /etc/ssl/private/*.key sudo chmod 644 /etc/ssl/certs/*.crt


## Step 6 — Restart Nginx Safely


After fixing configuration and permissions:

sudo systemctl restart nginx

Check status:

sudo systemctl status nginx

It should show:

Active: active (running)

Test by opening your website in a browser or:

curl http://localhost


## Step 7 — Check SELinux or Firewall (if applicable)


Sometimes Nginx cannot bind to ports due to security restrictions.

Check firewall

sudo ufw status

Allow HTTP/HTTPS:

sudo ufw allow 80/tcp sudo ufw allow 443/tcp

Check SELinux (CentOS/RHEL)

sestatus

If enabled, allow Nginx to bind ports:

sudo setsebool -P httpd_can_network_connect 1


## Step 8 — Remove Old PID Files


If Nginx was killed improperly, old PID file may block startup:

sudo rm /var/run/nginx.pid sudo systemctl start nginx


## Step 9 — Test Configuration After Every Change


Always test config before restarting:

sudo nginx -t

If “syntax is ok” → restart Nginx safely.




## Step 10 — Beginner-Friendly Checklist


ProblemDiagnosisFix
Nginx not runningsystemctl status nginxRead status message
Syntax errornginx -tFix configuration
Port conflictlsof -i :80Stop conflicting service
Permission issuels -l /var/www/htmlFix ownership/permissions
Firewall/SELinuxufw status, sestatusAllow ports / adjust SELinux
Old PID file/var/run/nginx.pidRemove and restart


## Conclusion


Nginx not starting is a common problem but almost always fixable with careful troubleshooting. By following these beginner-friendly steps, you can:

  • Identify configuration errors

  • Resolve port conflicts

  • Fix file permission issues

  • Check firewall and SELinux restrictions

  • Restart Nginx safely

With these steps, your websites should be running again in no time.


Advertisement
Back to Linuxserver