Flask应用程序目录和权限 [英] Flask App Directory and Permissions

查看:172
本文介绍了Flask应用程序目录和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Ubuntu服务器上构建了一个简单的应用程序,并将代码放在以下目录中:
主应用程序代码:/ home / user / flaskapp
WSGI Config:www / flaskapp / app。 wsgi



我的问题是:


  1. 应用代码的位置我的主目录在生产中没有问题?

  2. 我的文件夹权限是运行安全/安全的网站吗? 'flask_user',我应该给它任何特殊的权限或组?
  3. 我知道你使用Apache或Nginx作为你的Web服务器。如果这是正确的,我会把你的应用程序代码和app.wsgi文件放在你的主目录。



    将文件放在/ var / www中可以看到由外部世界在某些情况下(它,除非你明确指定它被您的网络服务器忽略/拒绝访问的网络服务器)。除非明确指定,否则将其放置/ home / user不允许被外界看到。

    至于权限,您需要给Apache服务器上的web服务器用户(通常是 www-data ),除非 flask_user 也是您的Web服务器用户)读取WSGI文件的权限,并可能执行权限。不知道有关其他Python文件的权限,但这很容易测试。首先拒绝您的Web服务器用户对文件的所有权限。如果这不起作用,请给它读取权限,等等,直到网站的工作。这将是所需的最低权限。


    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

    My questions are:

    1. Is the placement of the app's code in my home directory okay in production?
    2. What should I have my Folder Permissions be to run a safe/secure site?
    3. My Ubuntu Users name is 'flask_user', should i give it any special permissions or groups?

    Thanks in advanced!

    解决方案

    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.

    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.

    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应用程序目录和权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆