Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6056

nginx Permission denied on Ubuntu

$
0
0

I'm trying to set up my Django app with uWSGI and nginx by following this guide. I'm able to run my app with Django's development server, as well as being served directly from uWSGI.

I'm running everything on a university managed Ubuntu 16.04 virtual machine, and my user has sudo access.


My problem:
When getting to this bit of the tutorial, and try to fetch an image, I get a 403 error from nginx.
The next section results in a 502.

/var/log/nginx/error.log shows

connect() to unix:///me/myproject/media/image.jpg failed (13: Permission denied) while connecting to upstream

connect() to unix:///me/myproject/project.sock failed (13: Permission denied) while connecting to upstream

for the 403 and 502, respectively.

I have read multiple questions and guides (one here, another here and yet another one, and this is not all of them), changed my permissions and even moved my .sock to another folder (one of the SO answers recommended that).

What else can I try?


Update:

I mentioned it in a comment, but I've gotten a bit further. A part of the problem was that, apparently, the /home directory on my VM is NFS, which messes up a good many permissions.

What I've done:

  • I've set up my project in /var/www/myproject/
  • Run chown -R me:www-data myproject
  • Run chmod -R 764 myproject

My new results:

  • Without nginx running:
    • uwsgi --http :8000 --module myproject.wsgi
      works perfectly
  • With nginx running:
    • uwsgi --socket myproject.sock --module myproject.wsgi --chmod-socket=664
      gives me a 502
    • uwsgi --ini myproject.ini
      gives me a 502

So now it's not a general permission issue, it's definitely an issue with nginx...


Update #2:
For the moment, everything is working when other has read-write permissions on the socket, and read-execute permissions on the rest of the project.
So nginx is not recognized as it should... I've double-checked, and nginx is running as the www-data user, which is the group-owner of my entire project, and which has read-execute permissions, just as other now has.


Here's my (updated) nginx.conf

# myproject_nginx.conf# the upstream component nginx needs to connect toupstream django {    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket    server unix:///var/www/myproject/myproject.sock;    # server 127.0.0.1:8001; # for a web port socket (we'll use this first)}# configuration of the serverserver {    # the port your site will be served on    listen      8000;    # the domain name it will serve for    server_name my.ip.goes.here; # substitute your machine's IP address or FQDN    charset     utf-8;    # max upload size    client_max_body_size 75M;   # adjust to taste    # Django media    location /media  {        alias /var/www/myproject/media;  # your Django project's media files - amend as required    }    location /static {        alias /var/www/myproject/static; # your Django project's static files - amend as required    # Finally, send all non-media requests to the Django server.    location / {        uwsgi_pass  django;        include     /var/www/myproject/uwsgi_params; # the uwsgi_params file you installed    }}

And here's my (updated) uwsgi.ini

# myproject_uwsgi.ini file[uwsgi]# Django-related settings# the base directory (full path)chdir          = /var/www/myproject# Django's wsgi filemodule         = myproject.wsgi# the virtualenv (full path)home           = /var/www/myenv# process-related settingsmaster         = true# maximum number of worker processesprocesses      = 10# the socket (full path)socket         = /var/www/myproject/myproject.sock# ... with appropriate permissions - may be neededchmod-socket   = 666uid            = megid            = www-data# clear environment on exitvacuum         = true

Viewing all articles
Browse latest Browse all 6056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>