简体   繁体   English

Apache上的Django Admin静态文件

[英]Django Admin Static Files on Apache

There are quite a few posts on here regarding the same subject, I've tried as many as I thought applicable. 关于同一主题,这里有很多帖子,我已经尝试了尽可能多的帖子。 Yet, I still have this error. 但是,我仍然有此错误。 Everything is being served fine for a django site I've built except the static files for admin. 对于我构建的Django网站,一切正常,除了用于admin的静态文件。

Versions: Django 1.6, Apache 2.4.7, Ubuntu 14.04 版本:Django 1.6,Apache 2.4.7,Ubuntu 14.04

Ok - I have ran manage.py collectstatic and here is the static folder: 好的-我已经运行了manage.py collectstatic,这是静态文件夹:

/srv/bahai-site/bahai-site/soul/static

This contains four folders: 1) admin/ 2) bootstrap/ 3) core/ and 4) flags/ 它包含四个文件夹:1)管理员/ 2)引导程序/ 3)核心/和4)标志/

Within these folders, I can see all expected static files and that they contain the code I'd expect. 在这些文件夹中,我可以看到所有期望的静态文件,并且它们包含我期望的代码。

When looking at a static file on the site itself, something like /static/core/css/desktop_992.css loads correctly while /static/admin/css/base.css throws a 404. 在网站本身上查看静态文件时,/ static / core / css / desktop_992.css之类的东西会正确加载,而/static/admin/css/base.css会抛出404。

Apache directives in http.conf: http.conf中的Apache指令:

Alias /static/ /srv/bahai-site/bahai-site/soul/static/

<Directory /srv/bahai-site/bahai-site/soul/static/>
Allow from all
</Directory>

WSGIScriptAlias / /srv/bahai-site/soul/soul/wsgi.py
WSGIPythonPath /srv/bahai-site/soul/soul:/srv/envelope/bahai-site/lib/python2.7/site-packages

<Directory /srv/bahai-site/soul/soul>
<Files wsgi.py>
Allow from all
</Files>
</Directory>

Side question: notice the WSGIScriptAlias and WSGIPythonPath only contains one "bahai-site/" directory level, instead of the two that actually exist after "/srv/". 附带的问题:注意WSGIScriptAlias和WSGIPythonPath仅包含一个“ bahai-site /”目录级别,而不是“ / srv /”之后实际存在的两个目录级别。 Why is the site running fine? 为什么网站运行正常? Shouldn't that be causing a problem? 那不是应该引起问题吗?

Anyway, what am I doing wrong here? 无论如何,我在这里做错了什么? How do I get these admin static files up and running? 如何启动并运行这些管理静态文件?

as far as the pythonpath is concerned I personally don't include that in my apache virtual host config file and it works. 就pythonpath而言,我个人不将其包含在我的apache虚拟主机配置文件中,并且它可以工作。 Maybe that's not needed? 也许不需要? Honestly I'm not all that well versed in server installations. 老实说,我对服务器安装不是很精通。 It defintely seems like a permission issue. 绝对似乎是一个权限问题。

I would run collectstatic using sudo, then I would also make sure the static folder has www-data group permission which is the permission apache uses out of the box. 我将使用sudo运行collectstatic,然后还要确保静态文件夹具有www-data group权限,这是apache开箱即用的权限。

If you need help setting permissions on a folder in Ubuntu check out this link here. 如果需要帮助在Ubuntu中设置文件夹权限,请在此处查看此链接。 https://askubuntu.com/questions/244406/how-do-i-give-www-data-user-to-a-folder-in-my-home-folder https://askubuntu.com/questions/244406/how-do-i-give-www-data-user-to-a-folder-in-my-home-folder

The problem was that I had updated two different configuration files for Apache with competing directives. 问题是我用竞争指令为Apache更新了两个不同的配置文件。

Note to Other Beginners: 其他初学者注意事项:

Directives (ie things like ...) can be placed in any file in the apache2 root -- in my case that was any file within /etc/apache2/. 指令(例如...之类的东西)可以放在apache2根目录下的任何文件中-在我的情况下,它是/ etc / apache2 /中的任何文件。 (Question to advanced users: is this only for Ubuntu? Or pretty much any Linux/Unix?) This will confuse you because, if you solve a problem using information from multiple online posts/documents, you'll likely have a smorgasbord of various people's Apache configuration preferences/styles. (对高级用户的问题:这仅适用于Ubuntu?还是几乎所有的Linux / Unix?)这会使您感到困惑,因为,如果您使用多个在线文章/文档中的信息来解决问题,则可能会有各种各样的麻烦。人们的Apache配置首选项/样式。 Hence my problem. 因此,我的问题。

As a beginner, you're probably expecting to see some kind of single location you can put your configurations/customizations (in this case directives) into. 作为一个初学者,您可能期望看到某种单一位置,可以将您的配置/自定义(在本例中为指令)放入其中。 That's not the case on Apache. 在Apache上并非如此。 You can put any of these anywhere. 您可以将任何这些放置在任何地方。 This is probably good once you advance your knowledge of Apache but it sucks when you're starting out. 一旦您提高了对Apache的知识,这可能会很好,但是刚开始时很烂。

My fix here was to go through all the files I touched in the /etc/apache2/ folder and consolidate any rules into one place. 我的解决方法是浏览/ etc / apache2 /文件夹中所有涉及的文件,并将所有规则合并到一个位置。 This lead to me removing duplicate/conflicting rules, which solved the problem. 这导致我删除重复/冲突的规则,从而解决了问题。

Now I think I need to talk to a therapist.... 现在我想我需要和治疗师谈谈...。

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

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