我在displayable_links.js上收到500错误。我认为这与我的ssl设置有关。使用Django 1.9.1,Python 2.7.5,PostgreSQL 9.2.14和Mezzanine 4.1。发生在调试中,并在Gunicorn后面。我为允许的主机提供*只是为了消除这种可能性。它也直接在端口8000上发生。

我的nginc.conf:

 worker_processes  1;
error_log  /var/log/nginx/error.log;
error_log   /var/log/nginx/error.log  notice;
error_log   /var/log/nginx/error.log  info;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

server {
    listen       80  default_server;
    root  /opt/www/;
    return 301 https://www2.example.com$request_uri;
    gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
server {
    listen       443 ssl;
    server_name  www2.example.com;
    add_header X-Frame-Options SAMEORIGIN;
    server_name_in_redirect off;
     root  /opt/www/;
    gzip off;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain
               text/css
               application/json
               application/javascript
               application/x-javascript
               text/xml
               application/xml
               application/xml+rss
               text/javascript;
    ssl_certificate      /etc/httpd/conf.d/2016.example.com.crt;
    ssl_certificate_key  /etc/httpd/conf.d/2016.example.com.key;
    ssl_trusted_certificate /etc/httpd/conf.d/intermediate.crt;
    ssl_dhparam /etc/httpd/conf.d/dhparams.pem;
    add_header Strict-Transport-Security max-age=31536000;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_buffer_size 8k;
    ssl_session_cache shared:SSL:30m;
    ssl_session_timeout 30m;
    ssl_stapling on;
    resolver 8.8.8.8;
    ssl_stapling_verify on;

    ssl_prefer_server_ciphers  on;
    proxy_redirect off;
    location / {
         proxy_pass http://127.0.0.1:8000;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /static/ {
         autoindex on;
         root /opt/www/;
    }
}

}

还有我的settings.py:
from __future__ import absolute_import, unicode_literals
enter code here`enter code here`import os
    from django.utils.translation import ugettext_lazy as _
    SEARCH_MODEL_CHOICES = []
    PAGE_MENU_TEMPLATES = (
         (1, _("Top navigation bar"), "pages/menus/dropdown.html"),
         (2, _("Left-hand tree"), "pages/menus/tree.html"),
         (3, _("Footer"), "pages/menus/footer.html"),
    )
    PAGE_MENU_TEMPLATES_DEFAULT = (2,)
    USE_MODELTRANSLATION = False
    ALLOWED_HOSTS = ['*']
    SERVER_EMAIL = '[email protected]'
    ADMINS = [('example', '[email protected]'),]
    TIME_ZONE = 'UTC'
    USE_TZ = True
    LANGUAGE_CODE = "en"
    LANGUAGES = (
        ('en', _('English')),
    )
    SITE_TITLE = "example Systems"
    DEBUG = False
    SESSION_EXPIRE_AT_BROWSER_CLOSE = True
    SITE_ID = 1
    USE_I18N = False
    AUTHENTICATION_BACKENDS = ("mezzanine.core.auth_backends.MezzanineBackend",)
    FILE_UPLOAD_PERMISSIONS = 0o644
    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.postgresql",
            "NAME": "example",
            "USER": "example",
            "PASSWORD": "example",
            "HOST": "127.0.0.1",
            "PORT": "5432",
        }
    }
    PROJECT_APP_PATH = os.path.dirname(os.path.abspath(__file__))
    PROJECT_APP = os.path.basename(PROJECT_APP_PATH)
    PROJECT_ROOT = BASE_DIR = os.path.dirname(PROJECT_APP_PATH)
    CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_APP
    STATIC_URL = "https://www2.example.com/static/"
    STATIC_ROOT = "/opt/www/static/"

    MEDIA_URL = STATIC_URL + "media/"
    MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
    ROOT_URLCONF = "%s.urls" % PROJECT_APP
    TEMPLATES = [{u'APP_DIRS': True,
                  u'BACKEND': u'django.template.backends.django.DjangoTemplates',
                  u'DIRS': (u'/opt/www/modernbiz/theme/templates', u'/opt/www/templates'),
                  u'OPTIONS': {u'builtins': [u'mezzanine.template.loader_tags'],
                               u'context_processors': (u'django.contrib.auth.context_processors.auth',
                                                       u'django.contrib.messages.context_processors.messages',
                                                       u'django.core.context_processors.debug',
                                                       u'django.core.context_processors.i18n',
                                                       u'django.core.context_processors.static',
                                                       u'django.core.context_processors.media',
                                                       u'django.core.context_processors.request',
                                                       u'django.core.context_processors.tz',
                                                       u'mezzanine.conf.context_processors.settings',
                                                       u'mezzanine.pages.context_processors.page')}}]
    INSTALLED_APPS = (
        "modernbiz",
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.redirects",
        "django.contrib.sessions",
        "django.contrib.sites",
        "django.contrib.sitemaps",
        "django.contrib.staticfiles",
        "mezzanine.boot",
        "mezzanine.conf",
        "mezzanine.core",
        "mezzanine.generic",
        "mezzanine.pages",
        "mezzanine.blog",
        "mezzanine.forms",
        "mezzanine.galleries",
        "mezzanine.twitter",
        "howtos",
        "mezzanine.accounts",
        "mezzanine.mobile",
        "polls",
    )
    MIDDLEWARE_CLASSES = (
        "django.middleware.gzip.GZipMiddleware",
        'htmlmin.middleware.MarkRequestMiddleware',
        "mezzanine.core.middleware.UpdateCacheMiddleware",
        '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',
        "mezzanine.core.request.CurrentRequestMiddleware",
        "mezzanine.core.middleware.RedirectFallbackMiddleware",
        "mezzanine.core.middleware.TemplateForDeviceMiddleware",
        "mezzanine.core.middleware.TemplateForHostMiddleware",
        "mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware",
        "mezzanine.core.middleware.SitePermissionMiddleware",
        "mezzanine.pages.middleware.PageMiddleware",
        "mezzanine.core.middleware.FetchFromCacheMiddleware",
    )
    PACKAGE_NAME_FILEBROWSER = "filebrowser_safe"
    PACKAGE_NAME_GRAPPELLI = "grappelli_safe"
    OPTIONAL_APPS = (
        "debug_toolbar",
        "django_extensions",
        "compressor",
        PACKAGE_NAME_FILEBROWSER,
        PACKAGE_NAME_GRAPPELLI,
    )
    f = os.path.join(PROJECT_APP_PATH, "local_settings.py")
    if os.path.exists(f):
        exec(open(f, "rb").read())
    try:
        from mezzanine.utils.conf import set_dynamic_settings
    except ImportError:
        pass
    else:
        set_dynamic_settings(globals())
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
    COMPRESS_ENABLED = True
    COMPRESS_OFFLINE = True
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'verbose': {
                'format': '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s'
            }
        },
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'formatter': 'verbose',
                'filename': '/var/log/gunicorn/gunicorn.errors',
            }
        },
        'loggers': {
            'django.errors': {
                'level': 'DEBUG',
                'handlers': ['file'],
                'propagate': True,
            },
        }
    }

编辑后添加stacktrace:
Internal Server Error: /displayable_links.js
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib64/python2.7/site-packages/mezzanine/core/views.py", line 192, in displayable_links_js
    for url, obj in Displayable.objects.url_map(for_user=request.user).items():
  File "/usr/lib64/python2.7/site-packages/mezzanine/core/managers.py", line 366, in url_map
    home = self.model(title=_("Home"))
  File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 408, in __init__
    val = field.get_default()
  File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 902, in get_default
    if isinstance(field_default, self.remote_field.model):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
[01/Feb/2016 20:50:25] "GET /displayable_links.js HTTP/1.0" 500 6309

最佳答案

4.1版本几天前已修复此问题。因此,您需要暂时使用master分支,直到4.1.1或4.2。

https://github.com/stephenmcd/mezzanine/pull/1516

08-28 15:56