Nginx 监督配置

Nginx supervisord configuration

我在 localhost:9001 上有一个 supervisord 服务器 运行。 我正在尝试在 localhost/supervisord 提供服务。

nginx配置是这样的:

worker_processes 1;
error_log /var/log/nginx/error.log;
pid /tmp/nginx.pid;
#daemon off;

events {
  worker_connections 1024;
}

http {
    # MIME / Charset
    default_type application/octet-stream;
    charset utf-8;

    # Logging
    access_log /var/log/nginx/access.log;

    # Other params
    server_tokens off;
    tcp_nopush on;
    tcp_nodelay off;
    sendfile on;

    upstream supervisord {
        server localhost:9001;
    }

    server {
        listen 80;
          client_max_body_size 4G;
          keepalive_timeout 5;

        location ^~ /stylesheets {
          alias  /Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/ui/stylesheets;
          access_log off;
        }

        location ^~ /images {
          alias  /Users/ocervell/.virtualenvs/ndc-v3.3/lib/python2.7/site-packages/supervisor/ui/images;
          access_log off;
        }

        location /supervisord {
            # Set client IP / Proxy IP
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP  $remote_addr;

            # Set host header
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://supervisord/;
        }
    }
}

在添加 ^~ /images^~ /stylesheets 位置之前,页面返回 502 Bad Gateway.

通过以上配置我可以访问 localhost/supervisord 但页面上缺少 CSS。

我看到 css/图像在浏览器中正确加载:

但我在浏览器控制台中看到一条错误消息,它似乎是罪魁祸首:

浏览器中 localhost/stylesheets/supervisor.css 的 mimetype 显示为 octet-stream 而不是 text/css

浏览器中 localhost:9001/stylesheets/supervisor.css 的 mimetype 显示为正确的 text/css

如何解决这个错误?

我考虑过为静态文件动态重写 mimetype,但我不是 nginx 方面的专家并且不知道如何从 nginx 配置中做到这一点。

这真的很有趣,像将 web 界面放在透明反向代理后面这样一个明显的功能并不像它应该的那样容易配置。

无论如何,这就是我让反向代理与无法修改 root 的应用程序一起工作的方法,例如主管:

           location /supervisor {
           proxy_pass http://127.0.0.1:9001/;
           }

           location / {

            if ($http_referer ~ "^.*/supervisor"){
              return 301 /supervisor/$request_uri;
            }
          }

应用程序端请求将到达主要端点,但随后 NginX 会将它们重定向到 /supervisor EP

这在大多数情况下有效,但在大多数情况下无效 always.The 以下主管的网络功能将失败:

  1. 正在获取操作确认 - 您可以启动/停止服务,但结果页面将无法加载;直接去/supervisor EP看看结果

  2. 活尾不起作用;然而,有一个带有手动刷新的日志显示,它在 link 下使用程序名称工作。

无论如何,这种部分支持对我来说已经足够了,您可能会发现它也很有用。

我能够简单地使用它:

upstream supervisor {
  server 127.0.0.1:9001;
}

server {
  # ... 

  location /supervisor/ {
    proxy_pass  http://supervisor/;
  }
}

甚至在浏览器中工作,在 url 中有和没有结束斜杠(即 http://example.com/supervisor and http://example.com/supervisor/ 都工作)。 这对我来说是必须的!