Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Solve Common Nginx Errors
coder7475
coder7475

Posted on

     

Solve Common Nginx Errors

How To Troubleshoot Common Nginx Errors

Common commands to troubleshoot nginx:

  • sudo cat /var/log/nginx/error.log: This is used to print a log with a list of errors and details about them.
  • sudo nginx -t: This is used to check for syntax error in configuration.
  • systemctl status nginx: This is used to check if the Nginx service is active or inactive.

Troubleshooting with the Error Log

To get a full overview of the nginx errors happening, run:

sudo cat /var/log/nginx/error.log
Enter fullscreen modeExit fullscreen mode

Above command results in error log. Example:

2022/11/28 23:58:22[emerg] 168641#168641: invalid hostin"[::]443" of the"listen" directivein /etc/nginx/sites-enabled/test.do-community.com:122022/11/28 23:59:44[emerg] 168664#168664: invalid number of argumentsin"root" directivein /etc/nginx/sites-enabled/test.do-community.com:42022/11/29 00:00:19[emerg] 168701#168701:"server" directive is not allowed herein /etc/nginx/sites-enabled/test.do-community.com:62024/08/03 10:41:37[notice] 28504#28504: using inherited sockets from"6;7;"2024/08/03 10:52:29[notice] 31898#31898: signal process started2024/08/03 11:02:04[error] 31899#31899:*5 open()"/var/www/tech.local/foss" failed(2: No such file or directory), client: 127.0.0.1, server: tech.local, request:"GET /foss HTTP/1.1", host:"localhost", referrer:"http://localhost/"2024/08/03 11:02:45[error] 31899#31899:*5 open()"/var/www/tech.local/foss" failed(2: No such file or directory), client: 127.0.0.1, server: tech.local, request:"GET /foss HTTP/1.1", host:"localhost", referrer:"http://localhost/"2024/08/03 11:05:54[error] 31899#31899:*7 open()"/var/www/tech.local/foss" failed(2: No such file or directory), client: 127.0.0.1, server: tech.local, request:"GET /foss HTTP/1.1", host:"localhost", referrer:"http://localhost/"2024/08/03 11:28:19[notice] 43309#43309: signal process started2024/08/03 11:28:30[crit] 43310#43310:*31 connect() to unix:/this/is/error failed(2: No such file or directory)whileconnecting to upstream, client: 127.0.0.1, server: tech.local, request:"GET /500error HTTP/1.1", upstream:"fastcgi://unix:/this/is/error:", host:"localhost"2024/08/03 11:37:53[crit] 43310#43310:*37 connect() to unix:/this/is/error failed(2: No such file or directory)whileconnecting to upstream, client: 127.0.0.1, server: tech.local, request:"GET /500error HTTP/1.1", upstream:"fastcgi://unix:/this/is/error:", host:"localhost"
Enter fullscreen modeExit fullscreen mode

The log provideskey information about the specific error.
The error message is divided into:

  • first part: date and time
  • second part [...]: provides types of error message, e.g: notice, crit, error, emerg(emergency) etc.
  • last part: error message itself (with what file and specific line can be found)

Checking for Syntax Errors

Most common errors nginx has to do with syntax in configuration error. To check syntax error, run:

sudonginx-t
Enter fullscreen modeExit fullscreen mode

The output if everything is ok:

nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conftestis successful
Enter fullscreen modeExit fullscreen mode

If there is syntax errors, example of log:

[emerg] invalid hostin"[::]443" of the"listen" directivein /etc/nginx/sites-enabled/test.do-community.com:12nginx: configuration file /etc/nginx/nginx.conftestfailed
Enter fullscreen modeExit fullscreen mode

After verifying syntax is correct always reload nginx. Command:

sudosystemctl reload nginx# ORsudonginx-s reload
Enter fullscreen modeExit fullscreen mode

Troubleshooting withsystemctl status nginx

Always verify if nginx service is active and working on your system. Usesystemd init system:

  systemctl status nginx
Enter fullscreen modeExit fullscreen mode

If your service is running, it will read asactive (running) in output.

If your service is not running, it will read asinactive (dead) in the output. If that happens restart Nginx service:

sudosystemctl restart nginx
Enter fullscreen modeExit fullscreen mode

Verify if it has restarted with:

  systemctl status nginx
Enter fullscreen modeExit fullscreen mode

References

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a Software Engineer focusing on web development. I am currently exploring the world of DevOps Engineering.
  • Joined

More fromcoder7475

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp