2016-02-24 21 views
10

Tôi đang triển khai một dự án django trên apache2 sử dụng mod_wsgi, nhưng vấn đề là máy chủ không phục vụ trang và nó treo cứng trong 10 phút trước khi đưa ra một lỗi:Django + mod_wsgi + apache2: máy chủ bị treo

End of script output before headers 

Đây là tôi site-available/000-default.conf:

ServerAdmin [email protected] 
DocumentRoot /home/artfact/arTfact_webSite/ 
Alias /static /home/artfact/arTfact_webSite/static 
     <Directory /home/artfact/arTfact_webSite/static> 
     Order allow,deny 
     Allow from all 
     Require all granted 
     </Directory> 

     <Directory /home/artfact/arTfact_webSite> 
     Order allow,deny 
     Allow from all 
     <Files wsgi.py> 
         Require all granted 
     </Files> 
     </Directory> 

     WSGIDaemonProcess artfact_site processes=5 threads=25 python-path=/home/artfact/anaconda/lib/python2.7/site-packages/:/home/artfact/arTfact_webSite 

     WSGIProcessGroup artfact_site 
     WSGIScriptAlias//home/artfact/arTfact_webSite/arTfact_webSite/wsgi.py 

settings.py

""" 
Django settings for arTfact_webSite project. 

Generated by 'django-admin startproject' using Django 1.8.5. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.8/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.8/ref/settings/ 
""" 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = xxxx 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'website', 
    'blog', 
) 

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
    'django.middleware.security.SecurityMiddleware', 
) 

ROOT_URLCONF = 'arTfact_webSite.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'arTfact_webSite.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Internationalization 
# https://docs.djangoproject.com/en/1.8/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'Europe/Paris' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.8/howto/static-files/ 

STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

MEDIA_URL = '/media/' 
MEDIA_ROOT = os.path.join(BASE_DIR,'media') 

wsgi.py

""" 
WSGI config for arTfact_webSite project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ 
""" 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arTfact_webSite.settings") 

application = get_wsgi_application() 

cấu trúc dự án

arTfact_webSite/ 
├── arTfact_webSite 
│   ├── __init__.py 
│   ├── __init__.pyc 
│   ├── settings.py 
│   ├── settings.pyc 
│   ├── urls.py 
│   ├── urls.pyc 
│   ├── wsgi.py 
│   └── wsgi.pyc 
├── blog 
├── static 
├── media 
└── website 
    ├── admin.py 
    ├── admin.pyc 
    ├── forms.py 
    ├── forms.pyc 
    ├── general_analyser.py 
    ├── general_analyser.pyc 
    ├── __init__.py 
    ├── __init__.pyc 
    ├── migrations 
    │   ├── __init__.py 
    │   └── __init__.pyc 
    ├── models.py 
    ├── models.pyc 
    ├── send_mail.py 
    ├── send_mail.pyc 
    ├── static 
    │   └── website 
    ├── templates 
    │   └── website 
    ├── tests.py 
    ├── tests.pyc 
    ├── urls.py 
    ├── urls.pyc 
    ├── views.py 
    └── views.pyc 

Trong arTfact_webSite/urls.py

urlpatterns = [ 
    url(r'^/*', include('website.urls')), 
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

Trong website/urls.py

urlpatterns = [ 
     url(r'^$', views.index, name='index'), 
    ] 

tôi làm điều gì sai ở đây?

+0

'Kết thúc đầu ra kịch bản trước lỗi headers' có nghĩa là ứng dụng của bạn gặp sự cố trước khi gửi bất kỳ phản hồi nào. Hãy thử kiểm tra sau đây. Dừng apache, chuyển sang/home/artfact/arTfact_webSite/arTfact_webSite và thử chạy lệnh 'python manage.py runserver'.Nó sẽ bắt đầu một máy chủ phát triển, nhưng rất có thể là nó sẽ cho bạn một lỗi của một số loại, chỉ ra những gì đang xảy ra sai. –

Trả lời

-1

Bạn cần phải xác định một máy chủ hoặc ServerAlias ​​trong khối VirtualHost của bạn:

ServerName www.example.com 

Tôi giả định Apache của bạn configs trên là bên trong một khối VirtualHost như vậy:

<VirtualHost *:80> 
... 
</VirtualHost> 
1

Dường như bạn có một 'a' trong wsgi.py tập tin của bạn giữa các dòng

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arTfact_webSite.settings") 
a 
application = get_wsgi_application() 

không chắc chắn nếu điều này là trong tập tin thực tế của bạn là tốt.

0

Hãy thử sử dụng lệnh:

apachectl configtest

Điều này sẽ giúp bạn cô lập những gì bị phá vỡ trong cấu hình apache của bạn. Xem liên kết này để biết thêm thông tin: https://httpd.apache.org/docs/2.4/programs/apachectl.html

Nếu nó báo cáo 'Cú pháp OK', sau đó bạn biết rằng đó là một chi tiết vấn đề cấu hình chứ không phải là một vấn đề cú pháp cấu hình.

Nếu không, việc đăng nhật ký apache2 của bạn sẽ hữu ích.

Các vấn đề liên quan