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!
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:
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.
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.
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.
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:
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.
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.
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.
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
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
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.