hob*_*es3 44 python apache django mod-wsgi
让我感谢Stack Overflow社区的各位帮助我解决各种Django和Apache(带有mod_wsgi)错误.到目前为止,我已经询问了5个相关问题,现在我越来越接近在生产网站上获取我的内容了!
所以,我知道有这个很多类似的问题,我已经读了一堆 的 问题, 关于 服务 的静态 媒体 文件 上 的Django.
我读到了STATIC_URL
,STATIC_ROOT
(很快就会过时)ADMIN_MEDIA_PREFIX
,并Alias /media/ ...
在Apache配置中设置了一个.我试图逐个测试每个解决方案,但我无法正常工作.
这是我的管理网站现在的样子
我也有一个奇怪的情况,任何子域在我的服务器上工作.例如,我试图设置我的服务器,以便http://www.satoshi.example.com/允许我的正常(非Django)内容,而http://django.satoshi.example.com/将允许我的Django内容将被提供.但是目前任何子域名,无论是satoshi.example.com还是blahblahasdas.satoshi.example.com都在为我的Django文件提供服务(我知道因为我可以/admin
在两个站点上访问该页面,尽管它们将在不同的会话中).
反正这里是我这是运行在服务器上的文件CentOS
(不知道哪个版本)Apache 2.2.15
,Python 2.6.6
,django 1.3.1
,和mod_wsgi 3.2
.
我将发布我认为最相关的文件和配置如下:
每次重新启动时,Apache都会抛出这些错误
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [notice] SIGHUP received. Attempting to restart
[Wed Feb 29 00:45:36 2012] [error] Exception KeyError: KeyError(140249420548064,) in <module 'threading' from '/usr/lib64/python2.6/threading.pyc'> ignored
[Wed Feb 29 01:45:36 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Feb 29 01:45:36 2012] [notice] Digest: done
[Wed Feb 29 01:45:36 2012] [warn] mod_wsgi: Compiled for Python/2.6.2.
[Wed Feb 29 01:45:36 2012] [warn] mod_wsgi: Runtime using Python/2.6.6.
[Wed Feb 29 01:45:36 2012] [notice] Apache/2.2.15 (Unix) mod_auth_pgsql/2.0.3 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_wsgi/3.2 Python/2.6.6 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
Run Code Online (Sandbox Code Playgroud)
这是通过选项/var/www/html/mysite/apache/apache_django_wsgi.conf
加载到我httpd.conf
的NameVirtualHost *:80
<VirtualHost *:80>
ServerName django.satoshi.example.com
ErrorLog "/var/log/httpd/django_error_log"
WSGIDaemonProcess django
WSGIProcessGroup django
Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
<Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
<Directory "/var/www/html/mysite">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
WSGIScriptAlias / "/var/www/html/mysite/apache/django.wsgi"
<Directory "/var/www/html/mysite/apache">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这是 /var/www/html/mysite/apache/django.wsgi
import os
import sys
paths = [
'/var/www/html/mysite',
'/var/www/html',
'/usr/lib/python2.6/site-packages/',
]
for path in paths:
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)
最后这里是其中的一部分 /var/www/html/mysite/settings.py
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
Run Code Online (Sandbox Code Playgroud)
如果你们需要任何其他文件,请告诉我.提前致谢!
jpi*_*pic 28
我认为你应该改变:
Alias /media/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
Run Code Online (Sandbox Code Playgroud)
至:
Alias /static/admin/ "/usr/lib/python2.6/site-packages/django/contrib/admin/media"
Run Code Online (Sandbox Code Playgroud)
因为你有:
ADMIN_MEDIA_PREFIX = '/static/admin/'
Run Code Online (Sandbox Code Playgroud)
小智 16
那是因为你还没有设置你的STATIC文件......
添加到设置:
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/static/'
Run Code Online (Sandbox Code Playgroud)
然后运行"python manage.py collectstatic"
这将把所有文件放在STATIC_ROOT下STATIC_URL将服务...你不应该将Apache指向你的Python lib文件!
如果您还需要自己的应用程序特定的静态文件,请设置"STATICFILES_DIRS".
归档时间: |
|
查看次数: |
36652 次 |
最近记录: |