Django和Apache配置,页面未加载

时间:2016-01-11 20:21:14

标签: python django apache ubuntu

免责声明:我知道此问题已多次解决,但我遇到的错误与其他发布的问题不同。

我有一个Django应用程序,我试图配置Apache在网络上运行。我去加载some.example.com并且浏览器中没有显示任何内容。每当我重新启动Apache服务器时,错误日志中都会出现以下内容

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

编辑:在我的其他工作Django应用中查看错误日志我看到同样的RSA server...错误,所以我不认为这是导致错误的原因。< / p>

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

我主要关注thisthis教程。步骤进行:

  1. 创建Django应用程序(运行内置服务器工作,一切都完美加载)
  2. 创建虚拟环境,在
  3. 中安装Django
  4. 创建/etc/apache2/sites-available/some.example.com
  5. 创建符号链接到/etc/apache2/sites-enabled/some.example.com
  6. 编辑/etc/apache2/sites-available/some.example.com,如下所示
  7. 运行以下命令

    chown -R username:www-data some.example.com
    chmod 775 some.example.com
    chmod 664 some.example.com/db.sqlite3
    
  8. 我正在使用Django 1.7和Apache 2.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/sites-available/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>
    

    settings.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,
    )
    

0 个答案:

没有答案