Monday, 27 May 2013

Why nginx usually throws 403, Forbidden?

A. This problem is mostly because user (who is running the nginx) doesn't have the access of that resource.

Opne file /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /var/run/;

events {
        worker_connections 768;
        # multi_accept on;
server {
    listen          80;
    access_log  /var/log/nginx/localhost.access.log;
    index           index.html;
    root            /var/www/

Try these:
1. Open nginx.conf, locate user directive (change as per who has the access, may be www-date is good)
2. Nginx master process would be running using the user who start the nginx service may be the root, but nginx will use another user to create threads to serve the contents, which is configured in nginx.conf file. Note that this user only need to have read access of the directory which are set using root directive.
2. Go to directory which you set as root in location context (which is /var/www in above example) and check the access, ls -al should show
3. You can change the ownership of files and direcotry using command "chown -R usergroup.username directoryName"