Django和Apache配置,页面未加载

2024-09-30 18:13:37 发布

您现在位置:Python中文网/ 问答频道 /正文

免责声明:我知道这个问题已经解决了多次,但我遇到的错误与其他问题不同。在

我有一个Django应用程序,我正试图配置运行在web上的Apache。我去装货some.example.com网站而且浏览器中绝对没有显示任何内容。每当我重新启动Apache服务器时,错误日志中会显示以下内容

RSA server certificate CommonName (CN) `example.com' does NOT match server name!?

编辑:查看我其他正在工作的Django应用程序中的错误日志,我看到了相同的RSA server...错误,所以我不认为这是导致错误的原因。在

我已经做了很多次了,我甚至记录了我的过程,这样我就不会遇到同样的错误。我的文档化流程在过去一直有效,目前我的服务器上运行着多个Django应用程序。在过去,我收到过诸如“无法写入数据库”或“无法服务器静态文件”之类的错误,但我以前从未见过空白屏幕。我甚至在Django设置文件中有DEBUG = True。在

我主要遵循this和{a2}教程。步骤:

  1. 创建Django应用程序(运行内置服务器工作,一切加载完美)
  2. 创建虚拟环境,在里面安装Django
  3. 创建/etc/apache2/可用站点/some.example.com网站在
  4. 创建指向/etc/apache2/sites的符号链接已启用/some.example.com网站在
  5. 编辑/etc/apache2/可用站点/some.example.com网站如下所示
  6. 运行以下命令

    chown -R username:www-data some.example.com
    chmod 775 some.example.com
    chmod 664 some.example.com/db.sqlite3
    

我使用的是django1.7和apache2.2.22。在

在wsgi.py在

import site
site.addsitedir('/srv/www/some.example.com/heartstudyenv/lib/python2.7/site-packages')
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "heartstudy.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

/etc/apache2/可用站点/some.example.com网站在

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName some.example.com
    ServerAlias some.example.com
    DocumentRoot /srv/www/some.example.com

    Alias /static /srv/www/some.example.com/static
    <Directory /srv/www/some.example.com/static>
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /srv/www/some.example.com/heartstudy>
        <Files wsgi.py>
            Order deny,allow
        </Files>
    </Directory>

    WSGIDaemonProcess heartstudy python-path=/srv/www/some.example.com:/srv/www/some.example.com/heartstudyenv/lib/python2.7/site-packages
    WSGIProcessGroup heartstudy
    WSGIScriptAlias / /srv/www/wwwsomeexample.com/heartstudy/wsgi.py
 </VirtualHost>

 NameVirtualHost *:443
 <VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile    /etc/apache2/sslkey/_.example.com/_.example.com.crt
    SSLCertificateKeyFile /etc/apache2/sslkey/_.example.com/_.example.com.key

    ServerAdmin webmaster@localhost
    ServerName some.example.com
    ServerAlias some.example.com
    DocumentRoot /srv/www/some.example.com

    WSGIProcessGroup heartstudy
    WSGIScriptAlias / /srv/www/some.example.com/heartstudy/wsgi.py

    Alias /static /srv/www/some.example.com/static
    <Directory /srv/www/some.example.com/static>
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /srv/www/some.example.com/heartstudy>
        <Files wsgi.py>
            Allow from all
        </Files>
    </Directory>
    ErrorLog /srv/www/some.example.com/apache_error.log
</VirtualHost>

在设置.py在

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/some.example.com'
MEDIA_PATH = os.path.join(BASE_DIR, 'media')

SECRET_KEY = 'some_key'

DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['some.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',
    'tweets',
)

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 = 'heartstudy.urls'
WSGI_APPLICATION = 'heartstudy.wsgi.application'

LOGIN_URL = '/tweets/login/'
SITE_ID = 3

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

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/New_York'
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,
)

Tags: pathdjangocomwsgiosexamplewww错误