简体   繁体   English

uWSGI下的Python创建具有错误权限的文件和目录

[英]Python under uWSGI creates files and dirs with wrong permissions

I'm a newbie in Python developing. 我是Python开发的新手。

I write a small Python web app that creates some files and directories. 我写了一个小的Python Web应用程序,它创建了一些文件和目录。 When I run it in command line everything is ok. 当我在命令行中运行它时一切正常。 But under uWSGI all new files get -rw-rw-rw- mode, and directories - drwxrwxrwx instead of -rw-rw-r-- and drwxrwxr-x respectively. 但是在uWSGI下,所有新文件分别获得-rw-rw-rw-模式和目录 - drwxrwxrwx而不是-rw-rw-r--和drwxrwxr-x。

uWSGI configuration is default for Ubuntu, nothing special. uWSGI配置是Ubuntu的默认配置,没什么特别的。 uWSGI app ini file is simply like this: uWSGI app ini文件就像这样:

[uwsgi]
plugins=python

nginx config is like that: nginx配置是这样的:

server {

        listen 8080;

        access_log /path/to/logs/access.log;
        error_log /path/to/logs/error.log;

        location / {
                uwsgi_pass unix:/var/run/uwsgi/app/myapp/socket;
                include uwsgi_params;
                uwsgi_param UWSGI_PYHOME /path/to/myapp/.env/;
                uwsgi_param UWSGI_CHDIR /path/to/myapp/;
                uwsgi_param UWSGI_SCRIPT myapp;
        }

}

I guess problem is in insufficient uWSGI configuration, but I don't know what I have to do. 我想问题是uWSGI配置不足,但我不知道我该做什么。

This is caused by uWSGI's default umask of 000 which leaves all bits in place - which means a default of 666 for files or 777 for directories. 这是由uWSGI的默认umask 000引起的,它将所有位保留在原位 - 这意味着文件的默认值为666或目录的默认值为777。

You can chance this by setting the umask option on your uWSGI config file to the bits that should be removed. 您可以通过将uWSGI配置文件上的umask选项设置为应删除的位来实现此目的。 For example, to get 644/755, you'd use an umask of 022 which cleary the write flag for group/other (777-022 = 755, 666-022 = 644) 例如,要获得644/755,您将使用022的umask来清除组/其他的写标志(777-022 = 755,666-022 = 644)

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

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