Problem Description
Just want to help somebody out. yes ,you just want to serve static file using nginx, and you got everything right in **nginx.conf**:
location /static {
autoindex on;
#root /root/downloads/boxes/;
alias /root/downloads/boxes/;
}
But , in the end , you failed. You got "403 forbidden" from browser...
----------------------------------------**The Answer Below:**----------------------------------------
The Solution is very Simple:
----------------------------------------
**Way 1 : Run nginx as the user as the '/root/downloads/boxes/' owner**
In **nginx.conf** :
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
YES, in the first line "**#user noboy;**" , just delete "**#**" , and change "**nobody**" to your own username in Linux/OS X, i.e change to "**root**" for test. The restart nginx.
**Attention** , You'd better not run **nginx** as **root**! Here just for testing, it's dangerous for the Hacker.
For more reference , see [nginx (engine X) – What a Pain in the BUM! \[13: Permission denied\]][1]
[1]: http://nicholasorr.com/blog/2008/07/22/nginx-engine-x-what-a-pain-in-the-bum/
----------------------------------------
**Way 2 : Change '/root/downloads/boxes/' owner to 'www-data' or 'nobody'**
In **Terminal**:
ps aux | grep nginx
Get the username of running nginx . It should be **'www-data'** or **'nobody'** determined by the version of nginx. Then hit in Terminal(use **'www-data'** for example):
chown -R www-data:www-data /root/downloads/boxes/
------------------------------**One More Important Thing Is:**------------------------------
These parent directories **"/"**, **"/root"**, **"/root/downloads"** should give the execute(x) permission to **'www-data'** or **'nobody'**. i.e.
ls -al /root
chmod o+x /root
chmod o+x /root/downloads
For more reference , see [Resolving "403 Forbidden" error](http://nginxlibrary.com/403-forbidden-error/) and [Nginx 403 forbidden for all files](https://stackoverflow.com/questions/6795350/nginx-403-forbidden-for-all-files)
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?