diff --git a/src/pretix/base/templates/400_hostname.html b/src/pretix/base/templates/400_hostname.html new file mode 100644 index 0000000000..881d0582c5 --- /dev/null +++ b/src/pretix/base/templates/400_hostname.html @@ -0,0 +1,52 @@ +{% extends "error.html" %} +{% load i18n %} +{% load static %} +{% block title %}{% trans "Unknown host" %}{% endblock %} +{% block content %} + +
+

{% trans "Unknown host" %}

+

+ {% blocktrans trimmed with host=header_host %} + Your browser told us that you want to access "{{ header_host }}". Unfortunately, we don't have + any content for this domain. + {% endblocktrans %} +

+ {% if is_fresh_install %} +

+ {% blocktrans trimmed %} + It looks like this is a fresh installation of pretix. This error message is probably caused due to + the fact that either your configuration includes the wrong site URL or your reverse proxy is sending + the wrong header. + {% endblocktrans %} +

+
+
{% trans "Expected host according to configuration" %}
+
{{ site_host }}
+
{% trans "Received headers" %}
+
+ Host: {{ request.headers.Host }} + {% if xfh %} +
+ X-Forwarded-For: {{ xfh }} + {% if not settings.USE_X_FORWARDED_HOST %}({% trans "ignored" %}){% endif %} + {% endif %} +
+
{% trans "Derived host from headers" %}
+
{{ header_host }}
+
+ {% else %} +

+ {% blocktrans trimmed %} + If you just configured this as a domain for your ticket shop, you now need to set this up as a "custom domain" + in your organizer account. + {% endblocktrans %} +

+ {% endif %} + + +
+{% endblock %} diff --git a/src/pretix/multidomain/middlewares.py b/src/pretix/multidomain/middlewares.py index 566700bfed..985caff62d 100644 --- a/src/pretix/multidomain/middlewares.py +++ b/src/pretix/multidomain/middlewares.py @@ -43,6 +43,7 @@ from django.core.cache import cache from django.core.exceptions import DisallowedHost from django.http.request import split_domain_port from django.middleware.csrf import CsrfViewMiddleware as BaseCsrfMiddleware +from django.shortcuts import render from django.urls import set_urlconf from django.utils.cache import patch_vary_headers from django.utils.deprecation import MiddlewareMixin @@ -112,7 +113,15 @@ class MultiDomainMiddleware(MiddlewareMixin): elif settings.DEBUG or domain in LOCAL_HOST_NAMES: request.urlconf = "pretix.multidomain.maindomain_urlconf" else: - raise DisallowedHost("Unknown host: %r" % host) + with scopes_disabled(): + is_fresh_install = not Event.objects.exists() + return render(request, '400_hostname.html', { + 'header_host': domain, + 'site_host': default_domain, + 'settings': settings, + 'xfh': request.headers.get('X-Forwarded-Host'), + 'is_fresh_install': is_fresh_install, + }) else: raise DisallowedHost("Invalid HTTP_HOST header: %r." % host)