Fixing Permission Errors in /var/lib/nginx
327 words ยท 2 minutes
This is a brief post so that I personally remember the solution as it has occurred multiple times for me.
The Problem
After migrating to a new server OS, I started receiving quite a few permission errors like the one below. These popped up for various different websites I'm serving via Nginx on this server, but did not prevent the website from loading.
I found the errors in the standard log file:
while
) )
You can see that the error is 13: Permission denied
and it occurs in the /var/lib/nginx/tmp/
directory. In my case, I had thousands of errors where Nginx was denied permission to read/write files in this directory.
So how do I fix it?
The Solution
In order to resolve the issue, I had to ensure the /var/lib/nginx
directory is owned by Nginx. Mine was owned by the www
user and Nginx was not able to read or write files within that directory. This prevented Nginx from caching temporary files.
# Alpine Linux
# Other Distros
You may also be able to change the proxy_temp_path
in your Nginx config, but I did not try this. Here's a suggestion I found online that may work if the above solution does not:
server {
...
/tmp;
...
}
Finally, restart Nginx and your server should be able to cache temporary files again.
# Alpine Linux (OpenRC)
# Other Distros (systemd)