简体   繁体   English

Django-部署,静态为403,但应具有权限,wsgi + Apache

[英]Django - deployed, 403 for static but it should have permission, wsgi + Apache

my deployed Django project can't access the static files, I get 403 for all of them when inspecting in Chrome. 我部署的Django项目无法访问静态文件,在Chrome中进行检查时,我得到的所有文件均为403。

I added the following to my 000-default.conf where I also have the WSGIScriptAlias etc.: 我将以下内容添加到我的000-default.conf中,其中也包含WSGIScriptAlias等:

Alias /static/ /home/budget/static/deploy/
<Directory /home/budget/static/deploy>
Required all granted
</Directory/

The static files exist in the budget/static/deploy folder. 静态文件存在于budget / static / deploy文件夹中。 Should this not give the required permissions? 这不应该提供所需的权限吗? What do I have to change to get rid of the 403? 要摆脱403,我必须更改什么?

It is running on Ubuntu 16.04. 它在Ubuntu 16.04上运行。

Edit: 编辑:

settings.py: settings.py:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    #os.path.join(BASE_DIR, 'budget/static'),
    os.path.join(BASE_DIR, "static"),
    )

STATIC_ROOT = os.path.join(BASE_DIR, "static/deploy/")

There may be a couple of different things that cause your configuration not to work. 可能有几种不同的情况导致您的配置无法正常工作。 First of all, I would make sure that you are indeed modifying the proper Apache configuration file. 首先,我将确保您确实在修改正确的Apache配置文件。 You can run this command to check this: 您可以运行以下命令进行检查:

/usr/sbin/apachectl -V | grep SERVER_CONFIG_FILE | awk '{split($0,a,"="); print a[2]}' | sed s/\"//g

Then, to delegate other API requests to django through WSGI, you should also give the correct permissions to your wsgi file (maybe this is not absolutely required for mere static serving to work): 然后,要通过WSGI将其他API请求委托给django,您还应该为您的wsgi文件提供正确的权限(也许这并不是绝对静态工作所必需的):

<Directory /path/to/django/project/project>
   <Files wsgi.py>
       Require all granted
   </Files>
</Directory>

Next, set the process information to be used by Apache as well as your binding url for your project. 接下来,设置要由Apache使用的过程信息以及项目的绑定URL。

WSGIDaemonProcess myproject python-path=/path/to/django/project python-home=/path/to/your/venv
WSGIProcessGroup mydjangoproject
WSGIScriptAlias /binding/url /path/to/django/project/project/wsgi.py

Lastly, you may need to set up some permissions to allow www-data to read your media and static files and you should be all set. 最后,您可能需要设置一些权限,以允许www-data读取您的媒体和静态文件,并且您已经准备就绪。 Don't forget to restart Apache to apply the modifications. 不要忘记重新启动Apache以应用修改。

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

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