Fix Nginx 403 Forbidden Once Serving Static Files

It’s been 3 days I’m facing an issue on my nginx that always got an error 403 forbidden once I opening my static file on my website.

I’ve tried googling with these keywords, but still got no solution:
https://www.google.co.id/search?q=django+gunicorn+nginx+static+files+forbidden
https://www.google.co.id/search?q=nginx+403+forbidden
https://www.google.co.id/search?q=django+nginx+static+files+forbidden

The only one clue that I had from nginx logs is only “permission denied”.

$ sudo tail -f /var/log/nginx/error.log
$ 2016/02/13 08:27:23 [error] 19693#0: *14 open() "/root/projects/portofolio/static/admin/css/base.css" failed (13: Permission denied), client: 36.xx.xxx.xx, server: 128.xxx.xxx.xxx, request: "GET /static/admin/css/base.css HTTP/1.1", host: "128.xxx.xxx.xxx"

I have tried to change my project permission, my static file permission, user that execute my nginx and permission denied still appear. I have asked to some of my friends one of them told me that I have to check my “nginx.conf“.
At that time, I thought I need to check file permission, but I think that I misunderstanding with my friend suggestion. Then I checked my “nginx.conf” and yeahhh!! I just know that “nginx.conf” had user config that we have to set.
By default “nginx.conf” user is “www-data“.

user www-data;
worker_processes 4;
pid /run/nginx.pid;

Then I replaced with my VPS user and solved my problem. 😀

user my_user;
worker_processes 4;
pid /run/nginx.pid;

I’ve got really really good experience at this first deploying app.
Stupid, eh? 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s