简体   繁体   English

带有 SSL 的猎鹰服务器在几个小时/几天后停止工作

[英]Falcon server with SSL stops working after some hours/days

I set up a very basic Python API server with falcon along the example given in the documentation .我按照文档中给出的示例使用falcon设置了一个非常基本的 Python API 服务器。 And it seems to work just fine.它似乎工作得很好。

Now I extended the code to support HTTPS requests using SSL certificates现在我扩展代码以支持使用 SSL 证书的 HTTPS 请求

import ssl

httpd = simple_server.make_server('', 8000, app)
httpd.socket = ssl.wrap_socket(
        httpd.socket, server_side=True,
        certfile='cert.pem',
        keyfile='key.pem')
httpd.serve_forever()

And again, it seems to work and HTTPS requests are served perfectly fine...in the beginning.再一次,它似乎工作正常,并且 HTTPS 请求得到了很好的服务……一开始。

However, after a while -- maybe a few hours or 1-2 days (no heavy load during testing) -- the server hangs and no longer accepts any requests.然而,过了一会儿——可能是几个小时或 1-2 天(测试期间没有重负载)——服务器挂起并且不再接受任何请求。 Not even with Te.net I can make any kind of connection.即使使用 Te.net,我也无法建立任何类型的联系。 The server script doesn't show any errors, and Ubuntu tells me that some process is still listening on this port.服务器脚本没有显示任何错误,Ubuntu 告诉我某些进程仍在侦听此端口。

Where do I go from here?我从这里拨打 go 在哪里? I don't even know how to troubleshoot.我什至不知道如何排除故障。 With the basic HTTP server, I haven't experienced any issues so far使用基本的 HTTP 服务器,到目前为止我还没有遇到任何问题

As discussed in the above comments, wsgiref 's simple_server isn't really suitable for production.正如上面评论中所讨论的, wsgirefsimple_server并不真正适合生产。

Assuming your application is contained in app.py , and you installed gunicorn into your current Python (virtual) environment, you can run your application with TLS as:假设您的应用程序包含在app.py中,并且您将 gunicorn 安装到当前的gunicorn (虚拟)环境中,您可以使用 TLS 运行您的应用程序:

gunicorn -b 0.0.0.0:443 --workers 8 --certfile /path/to/your/cert/cert.pem --key=/pat/to/your/cert/privkey.pem --access-logfile - app:app

(You should of course tune the number of workers, threads, etc according to your application's needs.) (当然,您应该根据应用程序的需要调整工作人员、线程等的数量。)

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

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