0
votes

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/;
}
}
1
Aye! Is this issue resolved by any chance? ;) Maybe by adding a certain subdomain to the mix :P It could be a good thing to either post an answer yourself and accept it, or delete the post altogether if it's of no value to others. The former might be better. - Felix

1 Answers

0
votes

The issue wasn't related to nginx, turns out gunicorn doesn't support multiple workers with web socket. Changed my number of workers from 3 to 1.