我有一个Django项目,我刚刚使用Apache和mod_wsgi部署,它似乎工作得很好。然后我更改了Apache配置文件以允许HTTPS,现在我的管理站点无法正常工作(尽管常规站点可以同时使用http和https)。
首先,如果我转到http://www.example.com/admin或https://www.example.com/admin,我会得到"服务器错误(500)"。我的Apache错误日志中没有列出任何内容,但我在other_vhosts_access.log中获得以下行:
使用HTTPS:
"GET /admin/login/?next=/admin/ HTTP/1.1" 500 300 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"
使用HTTP:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /srv/www/www.example.com
Alias /static /srv/www/www.example.com/static
<Directory /srv/www/www.example.com/static>
Order allow,deny
Allow from all
</Directory>
<Directory /srv/www/www.example.com/my_app>
<Files wsgi.py>
Allow from all
</Files>
</Directory>
WSGIDaemonProcess my_app python-path=/srv/www/bcsurvey.wwbp.org:/srv/www/www.example.com/virtenv/lib/python2.7/site-packages
WSGIProcessGroup my_app
WSGIScriptAlias / /srv/www/www.example.com/my_app/wsgi.py
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/sslkey/mykey.crt
SSLCertificateKeyFile /etc/apache2/sslkey/mykey.crt
ServerAdmin webmaster@localhost
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /srv/www/www.example.com
WSGIProcessGroup my_app
WSGIScriptAlias / /srv/www/www.example.com/my_app/wsgi.py
Alias /static /srv/www/www.example.com/static
<Directory /srv/www/www.example.com/static>
Order allow,deny
Allow from all
</Directory>
<Directory /srv/www/www.example.com/my_app>
<Files wsgi.py>
Allow from all
</Files>
</Directory>
</VirtualHost>
其次,如果我使用我的管理员用户名和密码登录www.example.com然后转到www.example.com/admin我会获得标准管理面板(如果我使用HTTP)或者我得到管理面板减去任何CSS(当我使用HTTPS时)。
这是我当前的Apache配置文件(EDITED添加缺失/静态别名):
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')
STATIC_PATH = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = '/srv/www/www.example.com'
MEDIA_PATH = os.path.join(BASE_DIR, 'media')
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'mykey'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['www.example.com']
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'survey',
)
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',
)
ROOT_URLCONF = 'my_app.urls'
WSGI_APPLICATION = 'my_app.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = (
STATIC_PATH,
)
MEDIA_URL = '/media/'
MEDIAFILES_DIRS = (
MEDIA_PATH,
)
TEMPLATE_DIRS = (
TEMPLATE_PATH,
)
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.email.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myemail@email.com'
EMAIL_HOST_PASSWORD = 'myemailpassword'
DEFAULT_FROM_EMAIL = 'myemail@email.com'
DEFAULT_TO_EMAIL = 'to email'
这是我的settings.py文件:
onResult()
另外,我正在使用Django v.1.7。
答案 0 :(得分:2)
修改强> 实际错误是缺少 SITE_ID 设置。请参阅有关小调试会话的注释...
原始答案: 您在https配置中缺少/ static Alias。
https?
是否请求静态资产此外,您在https配置中错过了WSGIDaemonProcess语句。