以非根用户身份运行Gunicorn

2024-09-30 02:17:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用gunicornhttp服务器运行python应用程序。作为安全强化的一部分,我们正在从根用户转移到运行进程的专用用户。你知道吗

Gunicorn是否使用了任何文件(除了PID/config/app文件)?我害怕在不久的将来我们会遇到访问文件的权限问题


Tags: 文件用户服务器configapp应用程序权限进程
2条回答

如果你真的很担心,你可以用strace启动gunicorn,看看它会打开什么。以非root用户身份运行是一种非常标准的配置,gunicorn在概念上非常简单,因此如果它启动并运行一分钟,您可能会感觉不错。你知道吗

对于gunicorn,您确实需要担心的是心跳系统阻塞了所有内容,并且没有足够的线程导致负载平衡器查询无法得到响应。请参阅此处以获取有关修复此问题的建议:https://pythonspeed.com/articles/gunicorn-in-docker/

Gunicorn正在项目文件夹中创建临时文件:

  File "/home/**/.local/lib/python3.6/site-packages/gunicorn/pidfile.py", line 36, in create
    fd, fname = tempfile.mkstemp(dir=fdir)
  File "/usr/lib64/python3.6/tempfile.py", line 344, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "/usr/lib64/python3.6/tempfile.py", line 262, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
PermissionError: [Errno 13] Permission denied: '/src/tmpqg7t98e3'

因此拥有项目根文件夹以使其工作

相关问题 更多 >

    热门问题