uwsgi + flask 没有 HTTPS 'Server Hello'

问题描述 投票:0回答:0

我无法让 uwsgi 独立响应 TLS 握手。当我使用集成的非生产 flask Web 服务器(作为端口 443 的根目录)时它正在工作,例如:

# python -m flask run -h 0.0.0.0 -p 443 --cert fullchain.pem --key privkey.pem

这样 TLS 握手交换密钥并提供页面。

当我尝试使用 uwsgi 时,TLS 握手卡住了。浏览器发送“Client Hello”并从服务器获取“ACK”但没有“Server Hello”并且通信超时。

我正在使用这个 uwsgi.ini:

[uwsgi]
socket = /tmp/%n.sock
shared-socket = :443
https = =0,fullchain.pem,privkey.pem
uid = ubuntu
gid = ubuntu
master = true
vacuum = true
virtualenv = venv
wsgi-file = app.py
callable = app
plugin = python3

还有这个 hello world app.py:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def main():
    return "Hi!"

if __name__ == '__main__':
    app.run()

这是输出:

# uwsgi --ini uwsgi.ini 
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.20-debian (64bit) on [Mon Mar 13 11:08:52 2023] ***
compiled with version: 11.2.0 on 21 March 2022 11:00:44
os: Linux-5.15.0-1031-aws #35-Ubuntu SMP Fri Feb 10 02:07:18 UTC 2023
nodename: ip-172-26-8-252
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/ubuntu/hello
detected binary path: /usr/bin/uwsgi-core
uwsgi shared socket 0 bound to TCP address :443 fd 3
setgid() to 1000
set additional group 4 (adm)
set additional group 20 (dialout)
set additional group 24 (cdrom)
set additional group 25 (floppy)
set additional group 27 (sudo)
set additional group 29 (audio)
set additional group 30 (dip)
set additional group 44 (video)
set additional group 46 (plugdev)
set additional group 117 (netdev)
set additional group 118 (lxd)
setuid() to 1000
your processes number limit is 7830
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 4
Python version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
PEP 405 virtualenv detected: venv
Set PythonHome to venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x55a4862c1750
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145840 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x55a4862c1750 pid: 18569 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 18569)
spawned uWSGI worker 1 (pid: 18570, cores: 1)

我试过没有成功:

  • 不放弃特权以排除丢失对密钥的文件访问权限。
  • 为共享套接字加上前缀:shared-socket = 0.0.0.0:443
  • 使用挂载:mount = /=app.py
  • 使用非特权端口:shared-socket = :9443

我在带有 letsencrypt 证书的 lightsail 服务器上运行它。

我错过了什么?任何帮助表示赞赏。

python flask uwsgi
© www.soinside.com 2019 - 2024. All rights reserved.