Django: How can I access celery flower page in production mode?
Asked Answered
A

4

13

In development mode(local), it is really easy to access flower page (http://localhost:5555)

But in production mode, it is difficult to access flower page.

I'd like to access flower dashboard page with this url:
https://spacegraphy.choislaw.xyz/flower/ (Domain name : choislaw.xyz)

I refered http://flower.readthedocs.io/en/latest/reverse-proxy.html#reverse-proxy and this is what I did:

nginx.conf

  http {
      include       mime.types;
      default_type  application/octet-stream;
      sendfile        on;

      server {
          listen       80;
          server_name  spacegraphy.choislaw.xyz;

          client_max_body_size 4G;
          keepalive_timeout 5;

          return 301 https://$server_name$request_uri;
      }


      # HTTPS server
      server {
          listen       443 default_server ssl;
          server_name  spacegraphy.choislaw.xyz;

          client_max_body_size 4G;
          keepalive_timeout 5;

          ssl_certificate      /etc/letsencrypt/live/spacegraphy.choislaw.xyz/fullchain.pem;
          ssl_certificate_key  /etc/letsencrypt/live/spacegraphy.choislaw.xyz/privkey.pem;

          location / {
              proxy_pass_header X-CSRFToken;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto https;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header HOST $http_host;
              proxy_set_header X-NginX-Proxy true;

              proxy_pass http://127.0.0.1:4349;
              proxy_redirect off;
          }

          # Flower
          location /flower/ {
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto https;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header HOST $http_host;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection "upgrade";
              proxy_http_version 1.1;

             proxy_pass http://localhost:5555/;
             proxy_redirect off;
         }
     }
 }

And I execute flower server:

$ celery --workdir=spacegraphy/  --app=spacegraphy.celery:app flower

And I access https://spacegraphy.choislaw.xyz/flower/, it shows like this:

enter image description here

And If I click any link,

enter image description here

Did I miss something? Do I separate flower server from application server?

Btw, Is it usual to run flower server on production server?

Airlee answered 20/12, 2016 at 11:15 Comment(7)
No settings for static files and location /tasks/Aranyaka
How can I deal with it?Airlee
Is it usual to run flower server on production server? For me, only enable it for maintenance purpose.Aranyaka
@Jinje How can I set settings file for static files for flower?Airlee
may refer to example here: linkAranyaka
@Jinje static files might be located in my virtual environment's site-package/flower something. Is it the /path/to/flower/static ?Airlee
yes, path of the static folder of flower in the virtual environment packageAranyaka
E
12

you need change flower nginx conf to:

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

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

    # proxy_pass http://unix:/tmp/flower.sock:/;
    proxy_pass http://localhost:5555;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
}
Emptyhanded answered 6/12, 2017 at 17:4 Comment(0)
X
6

Actually you'll need both previous solutions at the same time:

  1. Run flower with --url-prefix=flower as @osmay88 mentioned
  2. Configure Nginx location section in next manner:

    location ~ ^/flower/? {
        proxy_pass http://<IP>:<PORT>;
        rewrite ^/flower/?(.*)$ /$1 break;
    }
    

When in use without url-prefix but with sub_filter then this will cause "Monitor" page to be empty.

Xerography answered 20/6, 2018 at 13:17 Comment(2)
@Vladimir Sh. I'm trying to use flower in production too, however my flower doesn't have real time response. do you know how to configure the nginx for real time monitoring?Winograd
@Winograd If I understand you correctly, there's a flag "celery flower --auto_refresh=True"Directrix
I
4

you can run flower with --url-prefix=flower

Indue answered 16/8, 2017 at 16:56 Comment(1)
Quick clarification: (I believe API might've changed) current docs indicate that this option should use an underscore (i.e. flower --url_prefix=flower) rather than a hyphen; source: flower.readthedocs.io/en/latest/config.html#url-prefixTouchy
J
4

from doc

$ flower --url_prefix=flower

nginx.conf

location /flower/ {
    rewrite ^/flower/(.*)$ /$1 break;
    proxy_pass http://example.com:5555;
    proxy_set_header Host $host;
}
Jelene answered 28/1, 2020 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.