Skip to main content

Error with Nginx

When running an Nginx test, the following response was being presented:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2022/08/04 07:05:54 [warn] 3105#3105: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2022/08/04 07:05:54 [crit] 3105#3105: pread() "/etc/nginx/sites-enabled/ckan" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

 

Permission issue

This error is shown because the user executing Nginx does not have permission to view the log file created by the Nginx process, which is most likely owned by www-data and not the user.  Running the command with sudo, if possible, or giving the user permissions on the error log will eliminate the error message being shown.

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

First, try the access rights to the folder and files for Nginx (www-data user in my case):

sudo chown -R www-data:www-data /var/log/nginx

Or if you want you can remove the directory and rebuild:

sudo rm -rf /var/log/nginx
sudo mkdir /var/log/nginx
sudo touch /var/log/nginx/error.log
sudo chown -R www-data:www-data /var/log/nginx

 

Critical issue

2022/08/04 07:05:54 [crit] 3105#3105: pread() "/etc/nginx/sites-enabled/ckan" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

In this instance, pread() which 'pread, pwrite - read from or write to a file descriptor at a given offset'.  So it attempting to read a file.  However, reviewing the structure on this path "/etc/nginx/sites-enables/ckan" I found that it's a directory.  In this directory, there is a file nginx.conf.

ckan -> /etc/nginx/sites-available/ckan/nginx.conf
default -> /etc/nginx/sites-available/default

One approach is to change the symlink to the file.  Take the following steps

Rename the ckan directory to something else

sudo mv ckan ckan-cc

Move the conf file and rename it

sudo mv ckan-cc/nginx.conf ckan

If you need to re-map the symlink, then run the command From the sites-enabled directory run the following command

ln -s ../sites-available/ckan

 

Test

Test Nginx configuration by running the command

nginx -t -c /etc/nginx/nginx.conf

or simply

nginx -t

My response was:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

 

Related articles

Andrew Fletcher18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...
Andrew Fletcher06 Mar 2024
Terminal command to find and replace
In many terminal text editors, you use find command as reference in Terminal commands - find.  How about find and replace.  This action depends on the specific text editor you're using in the terminal.  Here are a few common terminal text editors and how you can find and replace...