Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build uWSGI with SSL support to use the websocket handshake API function?

What I have: ubuntu 14.4 uwsgi running with flask (python) with nginx as reverse proxy.

What I want: running this example of WebSockets: https://github.com/zeekay/flask-uwsgi-websocket/blob/master/examples/echo/echo.py

When I'm running this application with chromepy on port 5000, it is working fine but when I try to run without chromepy I get an error

The error:

Thu Jun 12 12:58:24 2014 - you need to build uWSGI with SSL support to use the websocket handshake api function !!!
Traceback (most recent call last):
  File "/home/lab_alglab/rep/car/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/lab_alglab/rep/car/local/lib/python2.7/site-packages/flask_uwsgi_websocket/websocket.py", line 54, in __call__
    uwsgi.websocket_handshake(environ['HTTP_SEC_WEBSOCKET_KEY'], environ.get('HTTP_ORIGIN', ''))
IOError: unable to complete websocket handshake
like image 308
vovacooper Avatar asked Jun 12 '14 11:06

vovacooper


4 Answers

I had to install OpenSSL via brew. Then run this command.

CFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" UWSGI_PROFILE_OVERRIDE=ssl=true pip install uwsgi -Iv
like image 101
John Wheeler Avatar answered Nov 19 '22 08:11

John Wheeler


As one of the poster's below mentioned, you'll need the openssl headers, and if they're in a non-traditional place (for example on Mac OS-X) you have to let uWSGI know.

On Debian/Ubuntu install them with "apt-get install libssl-dev". They'll go in /usr/include/" which is part of UWSGI's automatic path. You should be done.

Mac OS-X El Capitan (10.11) removed the openssl headers. You can check common places with this command--they may have been installed by a package manager like brew or macports.

find /usr/local/include /usr/include /opt/local/include /usr/local/ssl/include -name openssl -type d 2> /dev/null

If that command returns nothing, you'll need to install the headers. You can install them with MacPorts (port install openssl) which will put them in /opt/local/include with a link in /usr/local/include. You can also install them directly, by downloading and untarballing openssl, running "./Configure darwin64-x86_64-cc", then "make", and finally "sudo make install".

Xcode's build utilities package a whole pre-defined build environment. With XCode projects that means developers have a common base to work from, and anything not in the base must be in XCode project. Building open source projects outside the base, gets a bit messy because dependencies like openssl live outside the base directories. You can give uwsgi's build chain ONE include directory to use. It doesn't support the PATH style : separator.

In most install cases, the following should work on OpenSSL.

UWSGI_INCLUDES=/usr/local/include/ pip install uwsgi  
like image 35
Cody B Avatar answered Nov 19 '22 09:11

Cody B


just install openssl development headers (libssl-dev) and rebuild uwsgi (its build system will automatically detect ssl availability)

like image 3
roberto Avatar answered Nov 19 '22 07:11

roberto


I fixed my version of this issue by installing uwsgi through pip (outside venv), and changing the init script (Ubuntu) /etc/init.d/uwsgi to run the newly installed 2.x branch (instead of 1.9).

Pip installed to /user/local/bin, so I changed the line daemon to: DAEMON="/usr/local/bin/uwsgi"

like image 1
Kjell-Bear Avatar answered Nov 19 '22 09:11

Kjell-Bear