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 Fletcher27 Oct 2023
Using OpenAI to summarise PDF
To use OpenAI to summarise text from a PDF using Python 3.11.6, you'll first need to extract the text from the PDF and then send it to the OpenAI API for summarisation. Preparation Set-uppip install python-dotenv langchain openai tiktoken pypdf pymupdf CodeThe current code is on my...
Andrew Fletcher20 Oct 2023
PermissionError: [Errno 13] Permission denied
Permission errorTraceback (most recent call last): File "/var/www/html/open-ai/summarise-ai.py", line 144, in <module> getfiles() File "/var/www/html/open-ai/summarise-ai.py", line 26, in getfiles summarise(filename) File "/var/www/html/open-ai/summarise-ai.py", line 105, in...
Andrew Fletcher19 Oct 2023
How to add an environment variable in Ubuntu
To set an environment variable on Ubuntu, can be achieved via a few options.  This depends on whether you want the variable to be system-wide or specific to a user's session.  Here are a couple of more common methods for setting environment variables:Setting environment variables for the...