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?

user3595632
  • 5,380
  • 10
  • 55
  • 111

4 Answers4

11

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;
}
neonua
  • 152
  • 2
  • 4
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.

Vladimir Sh.
  • 385
  • 4
  • 6
  • @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? – luvwinnie Jan 04 '20 at 09:46
  • @luvwinnie If I understand you correctly, there's a flag "celery flower --auto_refresh=True" – iChux Nov 03 '22 at 08:48
4

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

osmay88
  • 421
  • 3
  • 12
  • 2
    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: https://flower.readthedocs.io/en/latest/config.html#url-prefix – lgants Jan 03 '21 at 20:48
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;
}
Ilya Petukhov
  • 682
  • 7
  • 12