Python 通过Django上载用户图像时出现权限错误。服务器以root用户身份运行,目录具有775权限

Python 通过Django上载用户图像时出现权限错误。服务器以root用户身份运行,目录具有775权限,python,django,nginx,gunicorn,ubuntu-14.04,Python,Django,Nginx,Gunicorn,Ubuntu 14.04,在尝试上载图像时,在管理界面中创建新记录时,我遇到以下错误 权限被拒绝:“/home/jeffy/django_files/django_test/static/upload_files/1407616465_2016587_61djazqi8l.jpg” 相关设置.py变量: STATIC_ROOT = "/home/jeffy/django_files/django_test/static/" MEDIA_ROOT=STATIC_ROOT 产量 ls -l /home/jeffy/djan

在尝试上载图像时,在管理界面中创建新记录时,我遇到以下错误

权限被拒绝:“/home/jeffy/django_files/django_test/static/upload_files/1407616465_2016587_61djazqi8l.jpg”

相关设置.py变量:

STATIC_ROOT = "/home/jeffy/django_files/django_test/static/"
MEDIA_ROOT=STATIC_ROOT
产量

ls -l /home/jeffy/django_files/django_test/static/

服务器以用户jeffy的身份启动:

jeffy@originaldjangster:/etc/nginx/sites-available$ sudo service nginx start
jeffy@originaldjangster:/etc/nginx/sites-available$ sudo /home/jeffy/django_files/django_test_venv/bin/gunicorn -c /home/jeffy/django_files/django_test_venv/gunicorn_config.py django_test.wsgi
root
我将此代码放在settings.py的末尾

这就是为什么root在gunicorn服务器启动后打印出来


为什么不能上载此文件?

这是原始的gunicorn\u config.py文件:

command = '/home/jeffy/django_files/django_test_venv/bin/gunicorn'
pythonpath = '/home/jeffy/django_files/django_test'
bind = '127.0.0.1:8001'
workers = 1
user = 'nobody'
将nobody改为jeffy可以让它工作,尽管它在静态目录和媒体目录相等的情况下犹豫不决……我在静态目录旁边创建了一个媒体文件夹

这个设置只是为了炫耀我的Django排骨。如果这是一个生产环境,我确实认为以root用户身份运行服务器是个坏主意

不确定这个设置到底有多糟糕,但至少到目前为止它还在工作

import getpass
print(getpass.getuser())
command = '/home/jeffy/django_files/django_test_venv/bin/gunicorn'
pythonpath = '/home/jeffy/django_files/django_test'
bind = '127.0.0.1:8001'
workers = 1
user = 'nobody'