When I use nginx to serve my spotify django app with gunicorn socket handling communication, I would sometimes get Bad Request error during the user authentication callback. If gunicorn is configured as TCP with an ip and port, I don't experience the error, nor if I use django's manage.py runserver; user authenticates successfully. This intermittent issue seems to only occur when I'm using a socket connection. Checked nginx, gunicorn and django logs and didn't really get any info other than the 400 code.
Using tekore python library to access spotify's api.
Here's my nginx config:
upstream app_server {
server unix:/home/yg/Documents/projects/app/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name 192.168.0.26;
client_max_body_size 4G;
access_log /home/yg/Documents/projects/app/logs/nginx-access.log;
error_log /home/yg/Documents/projects/app/logs/nginx-error.log;
location /static/ {
alias /home/yg/Documents/projects/app/static/;
}
location /media/ {
alias /home/yg/Documents/projects/app/media/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_buffering off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/yg/Documents/projects/app/static/;
}
}