Tôi đã xem qua rất nhiều bài đăng có liên quan nhưng không có gì có vẻ hữu ích.
liên quan Thông tin:Apache 403 khi đang phục vụ các tệp tĩnh Django
Django phiên bản - 1,4
Apache phiên bản - 2,2
Python phiên bản - 2,7
OS - Xubuntu 12,04
DB - Mysql
Tôi đang cố gắng để có được Apache để phục vụ cả các ứng dụng django và các tập tin tĩnh. Vấn đề trở nên rõ ràng trong trang quản trị không hiển thị bất kỳ kiểu CSS hoặc hình ảnh nào. Trang web quản trị của tôi hiện tại trông giống như:
(tốt, tôi đã bao gồm hình ảnh nhưng ngăn xếp ngăn xếp không cho phép tôi. Có vẻ như trang quản trị của những người khác đã đăng về chủ đề này, xem Apache not serving django admin static files )
Các phần ứng dụng như trang đăng nhập của tôi và một số nội dung động hoạt động tốt, nhưng khi tôi cố gắng phân phối nội dung tĩnh, tôi nhận được lỗi 403. Ngoài ra, khi tôi cố gắng điều hướng đến biểu định kiểu theo cách thủ công bằng cách xem html được hiển thị của trang quản trị và nhấp vào liên kết đến biểu định kiểu tại
http://localhost/static/admin/css/base.css
Tôi nhận được lỗi 403. Tôi có thể điều hướng trong một thiết bị đầu cuối, và thay đổi quyền cho thư mục để người dùng www-data của Apache có quyền truy cập rõ ràng vào tất cả các tệp.
Dưới đây là các mảnh có liên quan của httpd.conf của tôi:
#AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1
Alias /media/ "/usr/local/wsgi/media/"
Alias /static/ "/usr/local/wsgi/static/"
<Directory "/usr/local/wsgi/static">
Order deny,allow
Allow from all
</Directory>
<Directory "/usr/local/wsgi/media">
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias/"/home/noah/Documents/Web/Basic/apache/django.wsgi"
<Directory "/usr/local/wsgi/scripts">
Order allow,deny
Allow from all
</Directory>
Theo lời khuyên của một người bạn tôi cũng đã copy ở trên để tôi sites-available mặc định:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www
TypesConfig /etc/mime.types
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/noah/Documents/Web/Basic/apache/ >
Options -Indexes FollowSymLinks
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
SetEnv DJANGO_SETTINGS_MODULE Basic.settings
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
#AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1
Alias /media "/usr/local/wsgi/media/"
Alias /static "/usr/local/wsgi/static/"
<Directory "/usr/local/wsgi/static">
Order deny,allow
Allow from all
</Directory>
<Directory "/usr/local/wsgi/media">
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias/"/home/noah/Documents/Web/Basic/apache/django.wsgi"
<Directory "/usr/local/wsgi/scripts">
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
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>
</VirtualHost>
Đây là của tôi django.wsgi
import os
import sys
path = '/home/noah/Documents/Web/Basic'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'Basic.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Và cuối cùng, đây là settings.py của tôi:
dự án# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/usr/local/wsgi/media/'
# 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 = 'http://localhost/media/'
# 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/"
STATIC_ROOT = '/usr/local/wsgi/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = 'http://localhost/static/'
# 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',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'bmc&epl=#u)r3elkvj#@90*cji*z^[email protected](ih'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'Basic.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'Basic.wsgi.application'
My Django 'cơ bản' sống trong ~/Documents/Web/được symlinked vào/var/www/
Any help is appreciated rất nhiều, và cho tôi biết nếu bạn cần bất kỳ tập tin hơn/thông tin.
bản sao có thể có của [Apache không phục vụ tệp tĩnh của quản trị viên django] (http://stackoverflow.com/questions/9500598/apache-not-serving-django-admin-static-files) – dm03514
Sự khác biệt nằm trong phiên bản django có các tính năng khác nhau và giải pháp ở đó không hiệu quả đối với tôi. – noah