title: 502 bad gateway because of permissions denied
body: <p>I am trying to deploy django project on digitalocean using nginx and gunicorn. 
  My project have the following structure</p>
  
  <pre><code>projects
  |_isli
    |_isli
      |_forecast #project directory
        |_manage.py
        |_forecast.sock
        |_forecast
          |_wsgi.py
          |_settings.py
          |_urls.py
  </code></pre>
  
  <p>My project created inside root directory without creating additional sudo user. I know that isn't right solution but i decide so. 
  In my <code>settings.py</code> file inside allowed hosts i specified ip address </p>
  
  <pre><code>ALLOWED_HOSTS = ['165.22.23.233']
  </code></pre>
  
  <p>In official digitalocean docs have tutorial about deploying django using nginx and gunicorn <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04" rel="nofollow noreferrer">Deploying django using Nginx and Gunicorn</a></p>
  
  <p>in this article used method where gunicorn setted up as socet here is my setup <code>/etc/systemd/system/gunicorn.service</code></p>
  
  <pre><code>[Unit]                                                        
  Description=gunicorn daemon                                   
  After=network.target
  
  
  [Service]                                                     
  User=root                                                   
  Group=root                                                  
  WorkingDirectory=/root/projects/isli/isli/forecast         
  ExecStart=/root/projects/isli/env/bin/gunicorn --log-level debug --error-logfile /var/log/gunicorn/error.log --access-logfile /var/log/gunicorn/access.log --workers 3 --bind unix:/root/projects/isli/isli/forecast/forecast.sock forecast.wsgi:application
  
  [Install]                                                     
  WantedBy=multi-user.target
  </code></pre>
  
  <p>after creating gunicorn.service file i run <code>systemctl start gunicorn</code> than <code>systemctl enable gunicorn</code> after it in my project directory was created forecast.sock file
  Than i setup nginx in <code>/etc/nginx/sites-available/forecast</code>  with following </p>
  
  <pre><code>server {
      listen 165.22.23.233:80;
  
      location = /favicon.ico {access_log off; log_not_found off;}                                                                                                                       
      location / { 
            include proxy_params;                                       
            proxy_pass http://unix:/root/projects/isli/isli/forecast/forecast.sock;
      }
   }
  </code></pre>
  
  <p>Than <code>systemctl restart nginx</code></p>
  
  <p>When i am trying to access <code>http://165.22.23.233:80</code> from browser its promt me 502 bad gateway. After it in <code>/var/log/nginx/error.log</code> file i see following </p>
  
  <pre><code>2020/02/09 16:29:01 [crit] 13533#13533: *11 connect() to unix:/root/projects/isli/isli/forecast/forecast.sock failed (
  13: Permission denied) while connecting to upstream, client: 178.176.218.110, server: , request: "GET / HTTP/1.1", upstream: "http://unix:/root/projects/isli/isli/forecast/forecast.sock:/", host: "165.22.23.233"
  </code></pre>
  
  <p>As i understood through this error my problem is that nginx can not access to <code>/root/projects/isli/isli/forecast/forecast.sock</code> file. After it i tried to check permissions to each entity of above path by </p>
  
  <pre><code>namei -nom /root/projects/isli/isli/forecast/forecast.sock
  </code></pre>
  
  <p>And here is output </p>
  
  <pre><code>f: /root/projects/isli/isli/forecast/forecast.sock
  drwxr-xr-x root root /
  drwx------ root root root
  drwxr-xr-x root root projects
  drwxr-xr-x root root isli
  drwxr-xr-x root root isli
  drwxr-xr-x root root forecast
  srwxrwxrwx root root forecast.sock
  </code></pre>
  
  <p>In output above root user have permissions to each entity to my socket  path but why error say me that permission denied </p>