'running flower behind a reverse proxy

The following is my nginx config:

    location /flower/ {
    rewrite /flower/(.*) /$1  break;

    sub_filter '="/' '="/flower/';
    sub_filter_last_modified on;
    sub_filter_once off;

    proxy_pass http://localhost:5555/;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

location /flower/static/ {
    sub_filter '/api' '/flower/api';
    sub_filter "'/monitor" "'/flower/monitor";
    sub_filter "'/worker" "'/flower/worker";
    sub_filter "'/'" "'/flower/'";
    sub_filter "'/dashboard'" "'/flower/dashboard'";
    sub_filter '"/update-dashboard"' '"/flower/update-dashboard"';
    sub_filter_types application/javascript;  # by default, sub_filter won't touch JS
    sub_filter_last_modified on;
    sub_filter_once off;

    alias <VIRTUALENV_PATH>/python3.4/site-packages/flower/static/;
    expires 30d;
}

Link for the above: https://github.com/mher/flower/issues/414

My flower version is 0.9.2 and nginx version is 1.12.1

I ran flower as follows:

$celery flower -A project_name --port=5555 --broker redis://broker_url:port

This renders the following: enter image description here

I ran flower as follows: (used --url_prefix=flower)

$ celery flower -A project_name --port=5555 --broker redis://broker_url:port --url_prefix=flower

This then rendered all the static files as shown: enter image description here

The problem occurs when I click on any of the tabs (say tasks) above as shown: enter image description here

I noticed that the url instead of being say: /flower/dashboard/ is /flower/flower/dashboard and so on.

What am I missing here? Anything to be changed in nginx config?



Solution 1:[1]

I'm not sure why are you using sub_filter in your nginx config.

Seems to me you are hosting flower in a particular url like xyz.com/flower that's why you are using sub_filter.

Though I have not used flower in such a way, but it seems to me wrong. There is another mistake which I could find, i.e. you are placing location /flower/static/ below location /flower/ hence all static requests are going to be handled by the location /flower/ code block

You nginx config should look something like this:

server {
    location /flower/static {
        alias  /the/path/to/flower/static;
    }
    location /flower {
        rewrite ^/flower/(.*)$ /$1 break;
        proxy_pass http://localhost:5555;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
    }
}

You could read more about the settings on the documentation and example

Solution 2:[2]

By Changing --url_prefix=flower to --url_prefix=/flower it was fixed for me.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 argo
Solution 2 omid akhgary