Django and Nginx through uwsgi is not working

1,234 views
Skip to first unread message

valerio orfano

unread,
Mar 16, 2017, 8:25:32 AM3/16/17
to Django users
Hi All

i ve created a django application not using virtual environment. I ve installed nginx and trying to integrate them via uwsgi application.
Here my configurations files.

    [uwsgi]
    chdir = /home/elastic/workspace/ES_Brevetti
    wsgi-file = ES_Brevetti/wsgi.py
    master = true
    processes = 5
    uid = nginx
    gid = nginx
    socket = unix:///socket/uwsgi.sock
    chmod-socket = 666
    vacuum = true

i've created the file /sockect/uwsgi.sock with permission 777  

chown nginx:nginx -R /sockect/uwsgi.sock

and below nginx conf file:

    upstream django {
        server unix:///socket/uwsgi.sock; # for a file socket
        #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    }
    server {
        listen 80;
        server_name 10.184.2.231;
        error_log /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
        charset utf-8;
       
        location /static/ {
            alias /home/elastic/workspace/ES_Brevetti;
        }

        location / {
            include         uwsgi_params;
            uwsgi_pass      unix:///socket/uwsgi.sock;
        }
    }


When i launch "systemctl start nginx" nginx is started with error:
 connect() to unix:///socket/uwsgi.sock failed (111: Connection refused) while connecting to upstream,
 
 When i run uwsgi --ini /etc/uwsgi/sites/ES_Brevetti.ini  it doesnt run with error:

    .....
    lock engine: pthread robust mutexes
    thunder lock: disabled (you can enable it with --thunder-lock)
    bind(): Permission denied [core/socket.c line 230]

   
What i am doing wrong? On google i can only see configurations with VENV while i am not using virtual environment.

Vijay Khemlani

unread,
Mar 16, 2017, 8:30:21 AM3/16/17
to django...@googlegroups.com
Not sure if a typo on your email, but your command says

"chown nginx:nginx -R /sockect/uwsgi.sock"

sockect ?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/891545d5-a99c-425d-8171-c6a9e43f5dd8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Tom Evans

unread,
Mar 16, 2017, 8:47:12 AM3/16/17
to django...@googlegroups.com
On Thu, Mar 16, 2017 at 12:25 PM, valerio orfano <ingor...@gmail.com> wrote:
> Hi All
>
> i ve created a django application not using virtual environment. I ve
> installed nginx and trying to integrate them via uwsgi application.
> Here my configurations files.
>
> [uwsgi]
> chdir = /home/elastic/workspace/ES_Brevetti
> wsgi-file = ES_Brevetti/wsgi.py
> master = true
> processes = 5
> uid = nginx
> gid = nginx
> socket = unix:///socket/uwsgi.sock
> chmod-socket = 666
> vacuum = true
>
> i've created the file /sockect/uwsgi.sock with permission 777
>
> chown nginx:nginx -R /sockect/uwsgi.sock

When you say you've "created the file /socket/uwsgi.sock", what have
you actually done?

You should have made a directory that uwsgi will be able to create a
unix socket in. You should not create a regular file, or even a named
fifo, with the same name as the socket, otherwise uwsgi will be unable
to create the socket.

Typically people do this by placing their socket files in /tmp or
/var/tmp, a world writeable sticky directory.

Cheers

Tom

valerio orfano

unread,
Mar 16, 2017, 11:25:03 AM3/16/17
to Django users
Ya it was a typo when writing

valerio orfano

unread,
Mar 16, 2017, 11:32:22 AM3/16/17
to Django users
Hi Tom if i dont create the file i get the error: unix:///tmp/uwsgi.sock failed (2: No such file or directory)

Melvyn Sopacua

unread,
Mar 16, 2017, 11:51:35 AM3/16/17
to django...@googlegroups.com

On Thursday 16 March 2017 05:25:32 valerio orfano wrote:

 

> Here my configurations files.

>

> [uwsgi]

> chdir = /home/elastic/workspace/ES_Brevetti

> wsgi-file = ES_Brevetti/wsgi.py

> master = true

> processes = 5

> uid = nginx

> gid = nginx

> socket = unix:///socket/uwsgi.sock

 

Where did you read the unix prototol is a network protocol that requires two slashes to indicate it is? And then add another to reference the root of the network domain?

 

> uwsgi_pass unix:///socket/uwsgi.sock;

 

See above.

--

Melvyn Sopacua

valerio orfano

unread,
Mar 16, 2017, 2:04:53 PM3/16/17
to Django users
I got it here "http://uwsgi-docs.readthedocs.io/en/latest/Nginx.html" and others actually 

Rafael E. Ferrero

unread,
Mar 16, 2017, 3:53:56 PM3/16/17
to django...@googlegroups.com
I've been using this tutorial on a Salix Linux and everythings goes well


Rafael E. Ferrero

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Melvyn Sopacua

unread,
Mar 16, 2017, 3:58:52 PM3/16/17
to django...@googlegroups.com

On Thursday 16 March 2017 11:04:53 valerio orfano wrote:

> http://uwsgi-docs.readthedocs.io/en/latest/Nginx.htm

*sigh*

 

http://nginx.org/en/docs/http/ngx_http_uwsgi_module.html#uwsgi_pass

 

unix:/path/to

 

Maybe unix:/// works, maybe it doesn't. But file:/// is supposed to be the exception to the URI rules, not the rule itself.

 

Also, just providing a plain path (socket = /var/run/uwsgi/myapp.sock) in uwsgi.ini works.

 

Of course, it will try to create the socket under the user uwsgi runs as, so permissions for the directory need to allow that.

--

Melvyn Sopacua

valerio orfano

unread,
Mar 17, 2017, 3:19:54 AM3/17/17
to Django users
I want to thank Melvyn publicly, without his support i wouldn't succed!

unix:/// in the uwsgi.ini file DOES NOT work (at least in Centos)

insted unix:/  WORKS OUT

Thanx you very much, i've spent days on this issue

Antonis Christofides

unread,
Mar 17, 2017, 6:18:44 AM3/17/17
to django...@googlegroups.com

Thanx you very much, i've spent days on this issue

I'm sorry to hear that, especially because when I was using uwsgi I was also spending days for various issues. All this pain went away when I started to use Gunicorn. You can read more about that in https://djangodeployment.com/2017/01/02/which-wsgi-server-should-i-use/.

Regards,

A.

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Vijay Khemlani

unread,
Mar 17, 2017, 8:31:42 AM3/17/17
to django...@googlegroups.com
I fail to see what's so complex of uwsgi for a simple deploy, my
typical configuration file has 8 lines
>> <mailto:django-users...@googlegroups.com>.
>> To post to this group, send email to django...@googlegroups.com
>> <mailto:django...@googlegroups.com>.
>> <https://groups.google.com/d/msgid/django-users/b6cfe3f2-ca74-44b3-830a-25c5f3c8afc3%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/be7e5d19-40b4-4d8a-c4e3-1812c634b090%40djangodeployment.com.
Reply all
Reply to author
Forward
0 new messages