Flask应用程序目录和权限的设置?

编程入门 行业动态 更新时间:2024-10-27 10:34:32
本文介绍了Flask应用程序目录和权限的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在ubuntu服务器上构建了一个简单的flask应用程序,并将代码放置在以下目录中:主要应用程式码:/home/user/flaskappWSGI配置:www/flaskapp/app.wsgi

I have built a simple flask app on ubuntu server and have placed the code in the following directories: Main app code: /home/user/flaskapp WSGI Config: www/flaskapp/app.wsgi

我的问题是:

  • 在生产中是否可以将应用程序的代码放置在我的主目录中?
  • 我应该在我的文件夹权限中拥有什么才能运行安全站点?
  • 我的Ubuntu用户名是'flask_user',我应该给它任何特殊的权限或组吗?
  • 推荐答案

    我了解您正在使用Apache或Nginx作为您的Web服务器.如果是正确的话,我会将您的应用程序代码和app.wsgi文件都放在您的主目录中.

    I understand you're using Apache or Nginx as your web server. If that's correct, I would place both your apps code and the app.wsgi file in your home directory.

    在/var/www中放置文件可以使外界在某些情况下可以看到该文件(除非您特别指定该文件被您的Web服务器忽略,否则拒绝Web服务器的访问).除非明确指定,否则将其放置在/home/user不允许外界看到它.

    Placing a file in /var/www allows it to be seen by the outside world in some cases (that it, unless you specifically specified it to be ignored by your webserver/deny access by the webserver). Placing it /home/user doesn't allow it to be seen by the outside world, unless explicitly specified.

    关于权限,您需要授予Web服务器用户(在Apache中通常为 www-data ,除非 flask_user 也是您的Web服务器用户)具有读取权限到WSGI文件中,并且还可能具有执行权限.不确定其他python文件的权限,但这很容易测试.首先,拒绝您的Web服务器用户对该文件的所有权限.如果那不起作用,请给它授予读取权限,依此类推,直到该站点正常运行为止.那将是所需的最低权限.

    As for permissions, You would need to give the web server user (usually www-data in Apache, unless flask_user is your web server user as well) read permission to the WSGI file, and probably also execute permissions. Not sure about permissions to the other python files, but that's easy to test. Start off with denying your web server user all permissions to the file. If that doesn't work, give it read permissions, and so on until the site works. That would be the minimum needed permission.

    更多推荐

    Flask应用程序目录和权限的设置?

    本文发布于:2023-11-11 21:26:11,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1579603.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:应用程序   权限   目录   Flask

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!