Flower: --url_prefix not supported anymore, so flower can only run on root now?

Created on 17 Jun 2015  路  40Comments  路  Source: mher/flower

Although using --url_prefix parameter does not give error when running Flower, but it doesn't work anymore. Also deprecated is written on this parameter in the latest source code. So does there exist an alternative to this parameter or from now on Flower can only be run on root?

enhancement

Most helpful comment

I reimplemented the support of --url-prefix. Please try the master version.

All 40 comments

I was also wondering the same thing, currently this is not usable for me because I want to run it on a nginx location. e.g: {url}/flower but the assets get requested on {url}/static

@spil-rkoopmans same thing here! I can access Flower urls manually like {host}/flower/broker, {host}/flower/tasks but not by clicking links on dashboard. And all the pages are without CSS and Javascript as these files are expected by flower at {host}/static but these are at {host}/flower/static for me.

Yup, so im downgrading to v0.7.3 which has the url_prefix option. I would like to know if there are plans to implement this in the future because there are more issues (open and closed) about this option.

I am seeing the same issue. Any update?

I'd like to run flower under a given url prefix. Much easier than setting up a new DNS entry for it.

+1 need url prefix

This option is definitely removed from the code. I've been looking for a matching commit message.

Flower's HTML is relatively simple, and I think I've been able to by pass the lack of `url_prefix'

location /flower/static/ {
    alias <VIRTUAL-ENV PATH>/lib/python2.6/site-packages/flower/static/;
    expires 30d;
}

location ~ ^/flower/? {
    # tampa office
    allow WHITELISTED_IP;
    # deny everything else
    deny  all;

    rewrite ^/flower/?(.*)$ /$1 break;

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

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_redirect off;
    proxy_pass http://FLOWER_HOST:FLOWER_PORT;
}

The implementation of --url_prefix was buggy and hard to maintain.
It was removed from the latest version. I'll try to come up with a better solution.

@mher just need to pull it out of the latest documentation I believe.

Hmm, sorry about that. I must have found it on an alternate version of the docs somewhere.

In addition to @pembo13's nginx config, I found there were many static references in the JS. This required multiple sub_filter directives to fix, which requires nginx 1.9.4. Unfortunately, at time of writing, the nginx ppa only has 1.9.3. I had to compile nginx myself, using the configure arguments here.

Edit: as of 2015-12-30, the nginx ppa includes support for multiple sub_filters.

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

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

    proxy_pass http://FLOWER_HOST:FLOWER_PORT;
    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>/python2.7/dist-packages/flower/static/;
    expires 30d;
}

theY4Kman suggestion would do very well in docs.

I've opened pull request #483 to add back support for --url_prefix

Django computes the url_prefix from the X-Forwarded-Host, right? Is there a way to make that work in flower?

Instead of adding this option back in, how about setting a global baseUrl variable of ./ and updating all JS references to be relative

+1 for @cornfeedhobo way to solve it, it should be much easier than now to have that.

+1

I think this feature is really useful and I agree that solution provided by @cornfeedhobo should be the easier way.

Meanwhile, another workaround could be to configure nginx to force redirect to the subfolder when the referer header contains the subfolder itself. A double check is required to avoid infinite redirect.

So, say your server name is example.com, flower is running on localhost:5555 and you want a base url example.com/flower, this should work:

   if ($http_referer ~* ^.*example.com/flower.*$ ) {
        set $flower_redirect 1;
    }
    if ($request_uri !~ ^/flower.*$) {
        set $flower_redirect "${flower_redirect}1";
    }
    if ($flower_redirect = 11) {
        rewrite ^(.*)$ /flower$1 permanent;
    }
    location ~ ^/flower(.*)$ {
        proxy_pass http://localhost:5555$1?$query_string;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

This is not a perfect solution, but you should be able to check the list of workers and tasks without having the very last version of nginx as @theY4Kman suggested.

Just as an FYI: as of 2015-12-30, the nginx ppa includes support for multiple sub_filters. So you'll still need the latest (>=1.9.4) nginx version for my suggestion, but on Deb systems, installation should be simple.

Can someone add a sample configuration to the docs?

@mher as I said, the solution I proposed is not working perfectly fine for some features: for instance the Monitor page doesn't show any graph. I didn't investigated too much, but I think there should be absolute path in js scripts used in that page.

@mher Is the fix really as simple as https://github.com/mher/flower/issues/414#issuecomment-152029804 indicates?

Any chance of that fix making it in or https://github.com/mher/flower/pull/483 being accepted?

I reimplemented the support of --url-prefix. Please try the master version.

Works . Thank you for the effort.

pip installed development github version.

launched flower with --url_prefix=flower option

rewrite ^/flower/(.*)$ /$1 break; with proxy_pass to flower server in nginx conf

awesome! thanks mher

I believe you missed some URLs, the graphs in the monitoring section do not show up when url prefix is set.

Anyone know when the version containing the fix will be available using pip?

It is already available @xeor

@janezkranjc I had the same problem and created a fix for that. You may try that out: https://github.com/mher/flower/pull/563/commits/8dd578e539564918e08009b690e410cbeb381e8d

I'm seeing a bunch of issues with oauth + url_prefix - @mher is this a known issue / should I file a separate issue? When I run it behind NGINX, e.g. http://my.domain/flower, it redirects me properly to oauth but redirects back to http://my.domain/# when finished. If I access it without NGINX, e.g. http://my.domain:8082/flower, it redirects to http://my.domain:8082/flower/login?next=%2F and says Error, page not found.

For the uWSGI fags (like me):

Got to work the equivalent of the old http://flower.readthedocs.io/en/latest/config.html#url-prefix NGINX instructions. Done with uWSGI Internal Routing.

[uwsgi]
# Serve the Flower dashboard
route = ^/flower goto:flower
route = (.*) last:
route-label = flower
route-uri = ^/flower/?(.*) rewrite:/$1
route-uri = ^/flower/?(.*) seturi:/$1
route = (.*) http:127.0.0.1:5555

Note that you will need _both_ route-uri instructions for rewrite: and seturi: otherwise uwsgi calls the wrong URL and you will get errors on the pages or on the assets.

(cc: @sbneto)

This one also works!

[uwsgi]
# Serve the Flower dashboard
route-uri = ^/flower/?(.*) seturi:/$1
route = ^/flower/?(.*) http:127.0.0.1:5555

@sbneto Any chance you can get that to work via cli options? Or only the ini file?

@thenewguy You can use via the CLI too.
See: http://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#configuring-uwsgi

Should be something alike:

uwsgi --route-uri "^/flower/?(.*) seturi:/$1" --route "route = ^/flower/?(.*) http:127.0.0.1:5555" ...

@alanjds Here is my previous uwsgi.ini file
```
[uwsgi]
env=DJANGO_SETTINGS_MODULE=lbb.settings.common
chdir=/opt/webapp
module=lbb.wsgi:application
reload-mercy=10
master=1
no-orphans=1
workers=4
enable-threads=1
single-interpreter=1
socket=:8000
harakiri=20
max-requests=5000
vacuum=1

If I add

route = ^/flower goto:flo:wer
route = (.) last:
route-label = flower
route-uri = ^/flower/?(.
) rewrite:/$1
route-uri = ^/flower/?(.) seturi:/$1
route = (.
) http:127.0.0.1:5555
```

and deploy to AWS. I am getting 404 not found error. do I have to add changes to nginx conf also?

At this point, someone should start a project to replace it, but that's my $0.02. I'm unsubscribing now because flower proved unstable at scale.

flower proved unstable at scale

馃

Was this page helpful?
0 / 5 - 0 ratings