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

8k views Asked by At

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?

4

There are 4 answers

0
neonua On

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;
}
2
Vladimir Sh. On

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.

1
osmay88 On

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

0
Ilya Petukhov On

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;
}