Lasciatemi ringraziare voi ragazzi della community di Stack Overflow per avermi aiutato con vari errori di Django e Apache (con mod_wsgi). Ho chiesto finora 5 domande correlate e ora mi sto avvicinando sempre di più ai miei contenuti su un sito di produzione!Apache che non serve i file statici admin di django
quindi so che ci sono molte domande simili su questo e ho letto un bunchofquestionsaboutservingstaticmediafilesonDjango.
ho letto su STATIC_URL
, STATIC_ROOT
, il (presto saranno obsoleti) ADMIN_MEDIA_PREFIX
, e la fissazione di un Alias /media/ ...
nella configurazione di Apache. Ho provato a testare ciascuna soluzione una per una, ma non riuscivo a far funzionare nulla.
Ecco ciò che il mio amministratore del sito si presenta come momento
Sto anche avendo un caso strano in cui qualsiasi sottodominio funziona sul mio server. Ad esempio, stavo tentando di configurare il mio server in modo che lo http://www.satoshi.example.com/ consentisse il mio normale contenuto (non-Django), mentre lo http://django.satoshi.example.com/ consentirebbe di offrire il mio contenuto Django. Ma attualmente qualsiasi sottodominio, sia satoshi.example.com o blahblahasdas.satoshi.example.com serve i miei file Django (lo so perché posso andare alla pagina /admin
su entrambi i siti, anche se saranno in sessioni diverse).
Comunque qui sono i miei file sul server che esegue CentOS
(non sono sicuro quale versione), Apache 2.2.15
, Python 2.6.6
, django 1.3.1
e mod_wsgi 3.2
.
mi post quello che penso sia i file e configurazione più rilevanti di seguito:
Apache getta questi errori ogni volta che ricomincio
[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
Qui è /var/www/html/mysite/apache/apache_django_wsgi.conf
che viene caricato nel mio httpd.conf
con l'opzione 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>
Ecco /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()
Ed ecco finalmente fa parte della /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',
)
Fatemi sapere se voi ragazzi hanno bisogno di qualsiasi altro file. Grazie in anticipo!
Ottima domanda. Hai svolto i compiti e fornito molte informazioni con cui lavorare. Continuate così. –
Ottima domanda, sono stato anche perso e l'aggiunta di ADMIN_MEDIA_PREFIX al mio file di impostazione ha fatto il trucco. – edu222