Ubuntu: Permission Denied - Django Deployment on Ubuntu 16.04 with web server Nginx



Question:

I am trying to deploy a django website on a Ubuntu 16.04 system using nginx but I am having issues.

ERRORS

Error I get from my nginx error.log file:

connect() to unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock failed (13: Permission denied) while connecting to upstream, client: 64.125.191.37, server: 173.255.210.63, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock:", host: "173.255.210.63", referrer: "http://173.255.210.63/"  

Status of uwgsi:

$ uwsgi status  uwsgi[25361]: thunder lock: disabled (you can enable it with --thunder-lock)  uwsgi[25361]: uwsgi socket 0 bound to UNIX address /home/teddycrepineau/contoursandcolors/contoursandcolors.sock fd 3  uwsgi[25361]: Python version: 3.5.2 (default, Nov 23 2017, 16:37:01)  [GCC 5.4.0 20160609]  uwsgi[25361]: !!! Python Home is not a directory: /home/teddycrepineau/Env/contoursandcolors !!!  uwsgi[25361]: Set PythonHome to /home/teddycrepineau/Env/contoursandcolors   uwsgi[25361]: Fatal Python error: Py_Initialize: Unable to get the locale encoding  uwsgi[25361]: ImportError: No module named 'encodings'  uwsgi[25361]: Current thread 0x00007f0ec8429700 (most recent call first):  uwsgi[25361]: Thu Apr 12 13:31:57 2018 - [emperor] curse the uwsgi instance contoursandcolors.ini (pid: 4955)  uwsgi[25361]: Thu Apr 12 13:32:00 2018 - [emperor] removed uwsgi instance contoursandcolors.ini  

SET UP

  • Using Python 3
  • Ubuntu 16.04
  • Using Virtualenvwrapper and virtualenv

Virtualenvwrapper set up

echo "export WORKON_HOME=~/Env" >> ~/.bashrc  echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc  

/etc/uwsgi/sites/contoursandcolors.ini:

[uwsgi]  project = contoursandcolors  uid = teddycrepineau  base = /home/%(uid)    chdir = %(base)/%(project)  home = %(base)/Env/%(project)  module = %(project).wsgi:application    master = true  processes = 2    socket = %(base)/%(project)/%(project).sock  chmod-socket = 664  vacuum = true  

/etc/nginx/sites-available/contoursandcolor:

server {          listen 80;          server_name 173.255.210.63;            location = /favicon.io { access_log off; log_not_found off; }            location /static/ {                  root /home/teddycrepineau/contoursandcolors;          }            location / {                  include uwsgi_params;                  uwsgi_pass unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock;          }  }  

/etc/systemd/system/uwsgi.service:

[Unit]  Description=uWSGI Emperor service    [Service]  ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown teddycrepineau:www-data /run/uwsgi'  ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites  Restart=always  KillSignal=SIGQUIT  Type=notify  NotifyAccess=all    [Install]  WantedBy=multi-user.target  

WHAT I'VE TRIED

  • Changed default python version from 2.7 to 3.5
  • Change socket file location from project to run (get me a file not found error)
  • I looked at quite a few StackExchange posts, but none have resolved my issue thus far

From what I read, my issue may be related to virtualenv location set up. Where should I go from here?


EDIT

I ended up using gunicorn (instead of uWSGI). It worked fine and was pretty easy to set up. Here is the link to the tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »