Report this

What is the reason for this report?

Nginx configuration test failed

Posted on July 18, 2020

Hello. I try to restart my nginx server but i have the following message: [crit] pread() “/etc/nginx/conf.d” failed (21: Is a directory) configuration file /etc/nginx/nginx.conf test failed

Can someone help me?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @oumarkhoudiadiop,

Are you running the config test with sudo?

Also, can you share your nginx.conf file here so that I could try to further advise you on what the problem might be?

Regards, Bobby

For anyone stumbling upon this thread:

The error message you’re encountering indicates that Nginx is trying to read a directory as if it were a file. This is typically caused by a misconfiguration in your Nginx configuration files. Let’s go through some steps to resolve this issue:

1. Check the Nginx Configuration File

The main Nginx configuration file is usually located at /etc/nginx/nginx.conf. Open this file and look for lines that include other files or directories. The typical directive for including other configuration files is include.

sudo nano /etc/nginx/nginx.conf

Look for a line similar to:

include /etc/nginx/conf.d;

If it’s trying to include a directory without specifying the file type, it should be changed to:

include /etc/nginx/conf.d/*.conf;

This line tells Nginx to include all files ending with .conf in the /etc/nginx/conf.d directory.

2. Check for Syntax Errors

After making changes, always check for syntax errors in your Nginx configuration files:

sudo nginx -t

This command will test your Nginx configuration for any syntax errors.

3. Review Additional Configuration Files

If you have additional configuration files under /etc/nginx/sites-available or /etc/nginx/sites-enabled, review them to ensure they don’t have similar issues. Sometimes, the error might be caused by a faulty configuration in one of these files.

4. Reload or Restart Nginx

Once you’ve resolved any configuration issues and confirmed there are no syntax errors, try reloading or restarting Nginx:

sudo systemctl reload nginx

The error message you’re encountering indicates that Nginx is trying to read a directory as if it were a file. This is typically caused by a misconfiguration in your Nginx configuration files. Let’s go through some steps to resolve this issue:

1. Check the Nginx Configuration File

The main Nginx configuration file is usually located at /etc/nginx/nginx.conf. Open this file and look for lines that include other files or directories. The typical directive for including other configuration files is include.

bashCopy code sudo nano /etc/nginx/nginx.conf

Look for a line similar to:

nginxCopy code include /etc/nginx/conf.d;

If it’s trying to include a directory without specifying the file type, it should be changed to:

nginxCopy code include /etc/nginx/conf.d/*.conf;

This line tells Nginx to include all files ending with .conf in the /etc/nginx/conf.d directory.

2. Check for Syntax Errors

After making changes, always check for syntax errors in your Nginx configuration files:

bashCopy code sudo nginx -t

This command will test your Nginx configuration for any syntax errors.

3. Review Additional Configuration Files

If you have additional configuration files under /etc/nginx/sites-available or /etc/nginx/sites-enabled, review them to ensure they don’t have similar issues. Sometimes, the error might be caused by a faulty configuration in one of these files.

4. Reload or Restart Nginx

Once you’ve resolved any configuration issues and confirmed there are no syntax errors, try reloading or restarting Nginx:

bashCopy code sudo systemctl reload nginx

or, if necessary,

bashCopy code sudo systemctl restart nginx

5. Check File and Directory Permissions

Ensure that the /etc/nginx/conf.d directory and its contents have the correct permissions. Nginx should have read access to these files and directories.

ls -l /etc/nginx/conf.d

6. Review Nginx Logs

If Nginx still fails to start, check the Nginx error logs for more detailed information about the issue:

sudo tail -f /var/log/nginx/error.log

This command will show the latest entries in the Nginx error log.

By following these steps, you should be able to identify and correct the configuration issue causing the error. Remember, the most common cause of this error is an incorrect include directive in one of the Nginx configuration files.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.