'CSRF verification fails after having deployed Django on nginx and waitress

I have used the build-in CSRF module in Django, which worked on localhost. After deploying on nginx and waitress on windows server, it gives me the following error:

Forbidden (403)
CSRF verification failed. Request aborted.

Help
Reason given for failure:

    Origin checking failed - https://95.18.243.298 does not match any trusted origins.

Have tried these setting in settings.py:

CSRF_TRUSTED_ORIGINS = ['95.18.243.298']

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

Figured it maybe have something to do with having implemented HTTPS. The nginx config looks like this:

server {
    listen      80;
    server_name DJANGO-WEB; # substitute your machine's IP address or FQDN

    return 301 https://$host$request_uri;

}

server {
    listen       443 ssl;
    server_name  DJANGO-WEB;
    charset      utf-8;

    ssl_certificate      C:/Users/Administrator/Desktop/certifikat.pem;
    ssl_certificate_key  C:/Users/Administrator/Desktop/privateKey.key;

    # max upload size
    client_max_body_size 75M;

    location /static {
        alias C:/Users/Administrator/itavis-web/static;
    }

    location / {
        proxy_pass http://localhost:8080; # See output from runserver.py
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Forwarded-Host $host;
    }
}

Hope someone can help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source