Solusi CSRF verification failed di Django

Masalah ini muncul ketika saya mengubah web server dari uwsgi ke gunicorn dan menggunakan proxy_pass di nginx, solusinya:

Tambahkan baris berikut di nginx.conf:

location / {
    proxy_set_header Host $http_host;
    proxy_pass http://127.0.0.1:8000;
    # proxy_set_header X-Forwarded-Host $server_name;
}

Kemudian tambahkan baris berikut di settings.py:

USE_X_FORWARDED_HOST = True

Done!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s