我一直在尝试不择手段地在 Apache SSL VirtualHost 中提供 /admin/static/ 服务,最好是通过 Apache(它将 SSL 流量转发到 Django Gunicorn 实例),或者禁止 Apache,至少 Gunicorn 提供服务静态内容,而我正在研究更好的解决方案。
我得到一个 Apache 服务的 403,我检查过的所有权限都表明 /usr/lib/python2.7/dist-packages/django/contrib/admin/static/ 目录(以及需要的父目录)是运行服务器的用户可读和可执行。
你能在下面的 VirtualHost 中看到任何错误,这可以解释为什么 Apache 没有将有问题的目录作为别名目录提供服务吗?
<VirtualHost *:443>
ServerName ccachicago.pragmatometer.com
Alias /media/ "/home/jonathan/ccachicago/media/"
<Directory "/home/jonathan/ccachicago/media/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Alias /admin/static/ "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/"
<Directory "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
ProxyPass /media/ !
ProxyPass /admin/static/ !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ssl.crt
SSLCertificateKeyFile /etc/apache2/ssl/ssl.key
ServerAdmin [email protected]
</VirtualHost>
- 更新 -
如果我注释掉拒绝/允许行,我会得到相同的 403 错误页面。日志文件有:
[Mon Jan 27 21:52:34.297099 2014] [authz_core:error] [pid 4818] [client 205.197.161.146:44895] AH01630: client denied by server configuration: /usr/lib/python2.7/dist-packages/django/contrib/admin/static/css
所以我的配置中的某些东西显然不起作用;我现在有:
<VirtualHost *:443>
ServerName ccachicago.pragmatometer.com
Alias /media/ "/home/jonathan/ccachicago/media/"
ErrorLog /var/log/apache2/error.log
<Directory "/home/jonathan/ccachicago/media/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Alias /admin/static/ "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/"
<Directory "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
#Allow from 0.0.0.0 ::1/128
#Allow from all
</Directory>
ProxyPass /media/ !
ProxyPass /admin/static/ !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ssl.crt
SSLCertificateKeyFile /etc/apache2/ssl/ssl.key
ServerAdmin [email protected]
</VirtualHost>
您只允许从 127.0.0.0 和 ::1 访问。您确定您正在通过这些地址访问该网站吗?我会首先禁用访问限制,然后看看会发生什么。
您的日志片段显示您没有从 127.0.0.1 或 ::1 访问服务器,因此您设置的访问限制在生效时将拒绝访问。