FrancescoL
FrancescoL

Reputation: 99

Plotly-Dash callback fired with empty url property behind Nginx

I have flask+dash website running on a gunicorn WSGi. All dash plots are managed via

@appReporting.callback(Output("page-content", "children"), [Input("url", "pathname")])

It works perfectly. As i put gunicorn behind nginx, the callback function is invoked, url is alwasy set to None.

Below Nginx configuration:

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\."
# gzip_comp_level 6;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

upstream app_servers {
    server  127.0.0.1:XXXX;     
}   

server {
    listen 80;
    
    return 301 https://$host$request_uri;   

}

server {
    listen 443 ssl;
    
    ssl_certificate certificate.pem;
    ssl_certificate_key key.pem;
    keepalive_timeout 70;

    
    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_ignore_headers Set-Cookie;
        proxy_hide_header    Set-Cookie;
        proxy_pass http://app_servers;
    }
    

}

Any clue? Even suggestion for debugging would be great.

################ Additional info, if I simply copy and paste the required url on the browser (so a GET request), callback is triggered, pathname set to the right value, a 404 error is generated.

Upvotes: 0

Views: 185

Answers (1)

FrancescoL
FrancescoL

Reputation: 99

Lots of troubleshooting and I hope this answer will help some developers.

To make it work I removed from nginx.conf the POST request from cache, changing from

proxy_cache_methods GET POST

to

proxy_cache_methods GET

Upvotes: 0

Related Questions