question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with uWSGI using unix sockets?

See original GitHub issue

Thanks for this great library!

I’m trying to use it with uWSGI via unix sockets without success, and am wondering if anyone has any ideas. The set up is Python 3.5 + Nginx + uWSGI.

(Sorry if this is not the right place to ask - I hope it may be helpful to others in similar situations.)

The Nginx part is working I think:

server {
  listen 80;

  location / {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:5000;
  }
}

And that’s because if I run the uWSGI server using HTTP, it works fine:

uwsgi --http :5000 --gevent 1000 --http-websockets --master --module myapp.wsgi --callable app

But if I run it using unix socket, it doesn’t. I have this Nginx setup:

server {
  listen 5000;

  gzip on;
  gzip_disable "msie6";
  gzip_min_length 1000;
  gzip_vary on;
  gzip_comp_level 6;
  gzip_types text/css application/json application/x-javascript text/javascript;

  location / {
    include uwsgi_params;
    uwsgi_pass unix:///tmp/myapp.sock;
  }
}

and the following uWSGI setup:

[uwsgi]
chdir = /home/ubuntu/myapp
module = myapp.wsgi
callable = app
home = /home/ubuntu/myapp/env

master = true
processes = 10
gevent = 1000
http-websockets = true

socket = /tmp/myapp.sock
chmod-socket = 660
vacuum = true

die-on-term = true

The error is WebSocket is closed before the connection is established.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
danqingcommented, Jan 11, 2017

Oh I got it working. Turns out you can’t specify the process param. Thanks again for the help!

Here’s the working config:

Nginx:

server {
  ...
  (non-socketio can still use uWSGI socket)

  location /socket.io/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://unix:///tmp/myapp.sock;
  }
}

uWSGI:

master = true
gevent = 500
http-websockets = true

http-socket = /tmp/myapp.sock
chmod-socket = 660
vacuum = true
3reactions
danqingcommented, Mar 2, 2017

Nothing fancy there:

location / {
    include uwsgi_params;
    uwsgi_pass unix:///tmp/myapp.sock;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up Django and your web server with uWSGI and nginx
In this tutorial we will set up uWSGI so that it creates a Unix socket, and serves responses to the web server via...
Read more >
Writing to a uWSGI unix socket - python - Stack Overflow
I have a Python wsgi app that is served by uWSGI behind NGinx. NGinx listens on the network and forwards requests to the...
Read more >
uWSGI TCP/IP host:port vs Unix socket - Server Fault
Changing back to localhost:port and no errors in the logs. The pages are loading with both configurations. We would prefer Unix sockets because...
Read more >
Problem with unix socket nginx-uwsgi - Raspberry Pi Forums
The web server is nginx and has a working php-fpm setup using a unix socket in the /run/php folder. I then added a...
Read more >
Django and Nginx through uwsgi is not working - Google Groups
Here my configurations files. ... When i launch "systemctl start nginx" nginx is started with error: connect() to unix:///socket/uwsgi.sock failed (111: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found