繁体   English   中英

如何构建具有 SSL 支持的 uWSGI 以使用 websocket 握手 API function?

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

我有什么: ubuntu 14.4 uwsgi 运行 flask (python) nginx 作为反向代理。

我想要什么:运行这个 WebSockets 示例: https://github.com/zeekay/flask-uwsgi-websocket/blob/master/examples/echo/echo.py

当我在端口 5000 上使用 chromepy 运行此应用程序时,它工作正常但是当我尝试在没有 chromepy 的情况下运行时出现错误

错误:

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

我不得不通过brew安装OpenSSL。 然后运行此命令。

CFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" UWSGI_PROFILE_OVERRIDE=ssl=true pip install uwsgi -Iv

作为下面提到的海报之一,你需要openssl标题,如果它们在非传统的地方(例如在Mac OS-X上),你必须让uWSGI知道。

在Debian / Ubuntu上安装“apt-get install libssl-dev”。 他们会进入/ usr / include /“这是UWSGI自动路径的一部分。你应该完成。

Mac OS-X El Capitan(10.11)删除了openssl标头。 您可以使用此命令检查常见位置 - 它们可能已由包管理器(如brew或macports)安装。

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

如果该命令什么都不返回,则需要安装标头。 您可以使用MacPorts(端口安装openssl)安装它们,这将把它们放在/ opt / local / include中,并带有/ usr / local / include中的链接。 您也可以通过下载和解压缩openssl,运行“./Configure darwin64-x86_64-cc”,然后“make”,最后“sudo make install”直接安装它们。

Xcode的构建实用程序打包整个预定义的构建环境。 使用XCode项目意味着开发人员可以使用共同的基础,并且基础中的任何内容都必须在XCode项目中。 在基础之外构建开源项目会变得有点混乱,因为像openssl这样的依赖项存在于基本目录之外。 您可以给uwsgi的构建链ONE包含要使用的目录。 它不支持PATH样式:分隔符。

在大多数安装情况下,以下内容应适用于OpenSSL。

UWSGI_INCLUDES=/usr/local/include/ pip install uwsgi  

只需安装openssl开发头文件(libssl-dev)并重建uwsgi(其构建系统将自动检测ssl可用性)

我通过pip(在venv之外)安装uwsgi,并更改init脚本(Ubuntu)/etc/init.d/uwsgi来运行新安装的2.x分支(而不是1.9)来修复我的这个问题的版本。

Pip安装到/ user / local / bin,所以我将行守护进程更改为:DAEMON =“/ usr / local / bin / uwsgi”

您可以使用LDFLAGS指定开发标头的位置。 另外,这可能发生在OS X上,因为El Capitan不再提供标题。

LDFLAGS="-L/usr/local/lib" pip install uwsgi --no-use-wheel

Ubuntu 20.04python 3.8.10pip作为系统包通过apt安装的解决方法:

# switch to root because system packages can't be changed without root privileges
# This is not necessary for user based environment like virtualenv or pyenv
sudo su -

# Uninstall previous version of `uwsgi` if exists
pip uninstall uwsgi

# Install libraries for SSL support
apt-get install libssl-dev

## Manually build uwsgi with SSL support
# set necessary lib paths
export CFLAGS="-I/usr/include/openssl"
# aarch64-linux-gnu folder used for ARM architecture and may be different for your env
# use [apt-file list libssl-dev] to check lib folders (apt-file should be additionally installed)
export LDFLAGS="-L/usr/lib/aarch64-linux-gnu"
# activate SSL support
export UWSGI_PROFILE_OVERRIDE=ssl=true
# build uwsgi using pip (--no-use-wheel depricated so used --no-binary instead)
# this command will install 2.0.20 version. Version may be changed or removed. It is not mandatory
pip install -I --no-binary=:all: --no-cache-dir uwsgi==2.0.20

# Check SSL support
uwsgi --help | grep https

预计 output:

    --https-socket                          bind to the specified UNIX/TCP socket using HTTPS protocol
    --https-socket-modifier1                force the specified modifier1 when using HTTPS protocol
    --https-socket-modifier2                force the specified modifier2 when using HTTPS protocol
    --https                                 add an https router/server on the specified address with specified certificate and key
    --https2                                add an https/spdy router/server using keyval options
    --https-export-cert                     export uwsgi variable HTTPS_CC containing the raw client certificate
    --https-session-context                 set the session id context to the specified value
    --http-to-https                         add an http router/server on the specified address and redirect all of the requests to https

基于此线程中的其他答案和评论。 感谢你们

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM