8

在开发模式(本地)下,访问花页非常容易(http://localhost:5555

但是在生产模式下,很难访问花页。

我想使用这个网址访问花卉仪表板页面:
https ://spacegraphy.choislaw.xyz/flower/(域名:choislaw.xyz)

我参考了http://flower.readthedocs.io/en/latest/reverse-proxy.html#reverse-proxy这就是我所做的:

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

我执行花服务器:

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

我访问https://spacegraphy.choislaw.xyz/flower/,它显示如下:

在此处输入图像描述

如果我点击任何链接,

在此处输入图像描述

我错过了什么?我是否将花服务器与应用程序服务器分开?

顺便说一句,通常在生产服务器上运行花服务器吗?

4

4 回答 4

8

您需要将花 nginx conf 更改为:

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;
}
于 2017-12-06T17:04:56.853 回答
5

实际上,您将同时需要两个先前的解决方案:

  1. 如@osmay88 所述,使用--url-prefix=flower运行花
  2. 以下一种方式配置 Nginx 位置部分:

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

当在没有url-prefix但使用sub_filter的情况下使用时,这将导致“Monitor”页面为空。

于 2018-06-20T13:17:00.453 回答
3

你可以用 --url-prefix=flower 运行花

于 2017-08-16T16:56:31.437 回答
2

来自文档

$ flower --url_prefix=flower

nginx.conf

location /flower/ {
    rewrite ^/flower/(.*)$ /$1 break;
    proxy_pass http://example.com:5555;
    proxy_set_header Host $host;
}
于 2020-01-28T12:40:13.553 回答