Can';t让Apache为django管理员静态文件提供服务
我正在尝试将Django部署到apache,但无法让它为我的静态管理文件提供服务。它似乎在/var/www/static下寻找它们,而我似乎无法改变这一点 管理网站似乎正在工作,除了样式。我得到一个标题和一个登录表。我的django应用程序也在运行。管理员的静态文件没有提供 使用Django 1.4.1 这些文件位于/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static下,并链接到from/home/dutt/vaccap/backend/static/admin apache错误日志显示Can';t让Apache为django管理员静态文件提供服务,django,apache,Django,Apache,我正在尝试将Django部署到apache,但无法让它为我的静态管理文件提供服务。它似乎在/var/www/static下寻找它们,而我似乎无法改变这一点 管理网站似乎正在工作,除了样式。我得到一个标题和一个登录表。我的django应用程序也在运行。管理员的静态文件没有提供 使用Django 1.4.1 这些文件位于/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static下,并链接到from/home/dutt/vacc
[Sun Sep 30 10:57:20 2012] [error] [client 192.168.1.10] File does not exist: /var/www/home, referer: http://dathui.example.com/vaccapp/admin/
[Sun Sep 30 10:57:20 2012] [error] [client 192.168.1.10] File does not exist: /var/www/home, referer: http://dathui.example.com/vaccapp/admin/
但我不知道如何改变它
在我的django站点配置中
<VirtualHost *:80>
ServerAdmin me@host.com
ServerRoot "/home/dutt/vaccapp"
DocumentRoot "/home/dutt/vaccapp"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/dutt/vaccapp/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /static/ "/home/dutt/vaccapp/backend/static/"
<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
没有向静态文件添加任何内容
这将添加到我的apache2.conf中
WSGIScriptAlias /vaccapp /home/dutt/vaccapp/backend/wsgi.py
WSGIPythonPath /home/dutt/vaccapp
<Directory /home/dutt/vaccapp>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIScriptAlias/vaccap/home/dutt/vaccap/backend/wsgi.py
WSGIPythonPath/home/dutt/vaccap
命令拒绝,允许
通融
ADMIN\u MEDIA\u PREFIX
默认设置为/static/ADMIN/
#在Django 1.4中已弃用(现在使用static\u URL+'ADMIN/'
。结果相同
以下是apache配置的修复程序:
Alias /static/admin "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static"
Alias /static "/home/dutt/vaccapp/backend/static"
<Directory "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias/static/admin”/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static”
别名/static”/home/dutt/vaccap/backend/static“
命令允许,拒绝
期权指数
通融
范欣德兴指数
WsgiScriptAlias必须从主apache配置移动到VirtualHost
经过长时间的讨论,我们发现问题在于Django没有正确安装管理静态…它们相互之间有符号链接(非常奇怪)。Django重新安装修复了它,现在它工作正常。我的低声誉迫使我写一个完整的答案,为Igor的答案添加一个小细节 我只是在配置中添加了apache配置部分,但这还不够。我必须更改:
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static"
到
在第一个
别名
和
指令中。就像Blazor一样,我必须使用原始版本的一个小变体。我的设置包括graphite web,它使用django admin。我只是发布它以供参考
我的apache虚拟主机:
<VirtualHost *:80>
ServerName graphite.myhost.com
Redirect permanent / https://graphite.myhost.com/
</VirtualHost>
<VirtualHost *:443>
ServerName graphite.myhost.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/graphite.cert
SSLCertificateKeyFile /etc/apache2/ssl/ssl_graphite.key
SSLStrictSNIVHostCheck on
WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
WSGIProcessGroup _graphite
WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi
AliasMatch ^/admin/(.*)static/admin(.*)$ /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/$2
<Directory "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/">
Order allow,deny
Allow from all
</Directory>
Alias /content/ /usr/share/graphite-web/static/
<Location "/content/">
SetHandler None
</Location>
<Location "/">
Order allow,deny
allow from all
AuthType Basic
AuthName "Restricted Zone"
AuthBasicProvider wsgi
WSGIAuthUserScript /var/www/django_auth.wsgi
Require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/graphite-web_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/graphite-web_access.log combined
</VirtualHost>
ServerName.myhost.com
重定向永久/https://graphite.myhost.com/
ServerName.myhost.com
斯伦金安
SSLCertificateFile/etc/apache2/ssl/graphite.cert
SSLCertificateKeyFile/etc/apache2/ssl/ssl\u.key
SSLStrictSNIVHostCheck on
WSGIDaemonProcess(graphite进程=5个线程=5个显示名称=“%$GROUP}”非活动超时=120用户=(graphite组=)
石墨
WSGIImportScript/usr/share/graphite web/graphite.wsgi进程组=_graphite应用程序组=%{GLOBAL}
WSGIScriptAlias//usr/share/graphite-web/graphite.wsgi
别名匹配^/admin/(*)static/admin(.*)$/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/$2
命令允许,拒绝
通融
别名/content//usr/share/graphite-web/static/
SetHandler无
命令允许,拒绝
通融
AuthType Basic
AuthName“限制区”
AuthBasicProvider wsgi
WSGIAuthUserScript/var/www/django_auth.wsgi
需要有效用户
ErrorLog${APACHE_LOG_DIR}/graphite-web_error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别警告
CustomLog${APACHE\u LOG\u DIR}/graphite-web\u access.LOG组合
我还添加了STATIC\u URL='STATIC/'
,以确保正则表达式没有任何问题。尝试使用next
python manage.py collectstatic
我在运行Django+Apache时遇到了类似的问题,Django管理站点丢失了所有样式。我就是这样解决的: apache配置文件:httpd-app.conf
Alias/static”/…path/to/your/django…/site packages/django/contrib/admin/static”
要求所有授权
在上面的
/…路径/to/your/django…/
中,您可以通过pip show django
找到它。您的应用程序正在使用此配置吗?您的应用程序的包名是否为backend
。应用程序正在工作,但它是一个后端,因此不使用任何静态文件。项目名为backend,应用程序名为dbaccess。看起来Apache正在运行在默认位置为您的文件添加ng,因此第一件事是将ServerRoot
添加到VirtualHost
(如果您的WSGIAlias将提供/,这将不是必需的。不过,如果有准确的请求URL也很好。请给我们一些404的访问日志。我尝试将ServerRoot添加到VirtualHost,但似乎没有任何改变。我正在查看apache2/error.log文件,但找不到任何404,只是文件不存在/var/www/static,referer…/vaccap/admin"lines.Q已用确切的ServerRoot更新。请检查access.log文件…它应位于同一目录中。欢迎使用堆栈溢出!请花一些时间阅读页面以熟悉SO Q&A格式。此答案看起来很危险。它会覆盖静态文件。不,alejandro是正确的。它不会覆盖静态文件Django从您的代码库中收集文件,它将覆盖Django正在服务的文件。您应该将静态根目录设置为某个空目录,然后运行collectstatic。Django从本质上收集文件并从静态根位置服务它们。这将映射它们的位置的责任与代码库的结构分离,即nd使您能够为静态文件使用单独的服务器。注意:,其中指出直接从代码库提供静态文件“效率极低,而且可能不安全”,并指出解决方案,其中指出使用collectstatic。
<VirtualHost *:80>
ServerName graphite.myhost.com
Redirect permanent / https://graphite.myhost.com/
</VirtualHost>
<VirtualHost *:443>
ServerName graphite.myhost.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/graphite.cert
SSLCertificateKeyFile /etc/apache2/ssl/ssl_graphite.key
SSLStrictSNIVHostCheck on
WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
WSGIProcessGroup _graphite
WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi
AliasMatch ^/admin/(.*)static/admin(.*)$ /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/$2
<Directory "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/">
Order allow,deny
Allow from all
</Directory>
Alias /content/ /usr/share/graphite-web/static/
<Location "/content/">
SetHandler None
</Location>
<Location "/">
Order allow,deny
allow from all
AuthType Basic
AuthName "Restricted Zone"
AuthBasicProvider wsgi
WSGIAuthUserScript /var/www/django_auth.wsgi
Require valid-user
</Location>
ErrorLog ${APACHE_LOG_DIR}/graphite-web_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/graphite-web_access.log combined
</VirtualHost>
python manage.py collectstatic
Alias /static "/...path/to/your/django.../site-packages/django/contrib/admin/static"
<Directory "/...path/to/your/django.../site-packages/django/contrib/admin/static">
Require all granted
</Directory>