【发布时间】:2015-09-08 15:36:07
【问题描述】:
我的网站正在使用:
python manage.py runserver 192.168.1.128:8000
我现在正在尝试使用 wsgi 部署它。 我相信 wsgi 安装正确(它位于 /usr/lib/apache2/modules/mod_wsgi.so)
我已经设置了以下设置文件:
settings.py:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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 = 'I have no idea if this needs to be secret :-)'
# SECURITY WARNING: don't run with debug turned on in production!
# This is over-ridden in settings-production
DEBUG = True
ALLOWED_HOSTS = ['*']
ADMINS = (
('test', 'test@thompco.com'),
)
# Application definition
INSTALLED_APPS = (
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'tester',
)
MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.common.CommonMiddleware',
)
ROOT_URLCONF = 'tester.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'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 = 'tester.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# These values are over-ridden in settings-private
try:
from settings_private import *
except:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DATABASE_NAME',
'USER': 'USER_NAME',
'PASSWORD': 'USER_PASSWORD',
'HOST': 'localhost',
'PORT': '3306',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
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/'
settings_production.py:
from settings import *
# Need the following to secure the final website (good candidate for a settings.production)
DEBUG = False
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_HTTPONLY = True
X_FRAME_OPTIONS = "DENY"
settings_private.py:
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'myuser',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '3306',
}
}
如果我跑步:
python manage.py check --deploy --settings=settings_production
我明白了:
System check identified no issues (0 silenced).
所以我认为至少 django 的东西已经准备好了。现在到阿帕奇。这是我迷路的地方。
我的 django 应用程序位于 /home/jordan/django/tester(这是我正在处理的 django 文件所在的位置。)
我尝试将以下内容添加到我的 /etc/apache2/apache2.conf 中:
Alias /static/ /home/jordan/django/tester/static
<Directory /home/jordan/django/tester/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /home/jordan/django/tester.wsgi
<Directory /home/jordan/django/tester>
Order deny,allow
Allow from all
</Directory>
我在该部分的 /etc/apache2/sites-enabled/000-default.conf 中添加了以下内容:
WSGIDaemonProcess tester
WSGIProcessGroup tester
WSGIScriptAlias / /home/jordan/django/tester/wsgi.py
然后我会这样做:
sudo /etc/init.d/apache2 restart
然后导航到 localhost/tester 并获得一个 403 禁止页面。
我很确定我在 apache 配置文件中遗漏了一些东西(可能很多!)。任何帮助都将受到欢迎。
【问题讨论】:
标签: python django apache debian