"Contradictory scheme headers" error after testing upgrading from Django 1.11 to 4.0.10

Hi everyone,

I’m still quite new to Django and server configurations, so I hope this question makes sense.

I’m currently testing a Django 4.0.10 deployment behind Nginx and Gunicorn. I noticed that when accessing the server via http://ip/testapi, Django returns this error:

Bad Request: Contradictory scheme headers

Interestingly, I have an older dev server running Django 1.11 with exactly the same Nginx configuration and the same value for SECURE_PROXY_SSL_HEADER:

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

The Nginx config includes:

proxy_set_header X-Forwarded-Proto "https";

Both servers are accessed via plain HTTP (not HTTPS), yet only the newer Django version returns this error.

My questions are:

  1. Is this error caused by new behavior introduced in Django itself?
  2. In which version was this “Contradictory scheme headers” check added?

I’d really appreciate any explanation, even in simple terms, or pointers to documentation. Thank you so much in advance for your help!

This is a gunicorn error, not a Django one.

This issue discusses the problem: