【问题标题】:Nginx supervisord configurationNginx supervisord 配置
【发布时间】:2017-02-10 20:16:24
【问题描述】:

我有一个在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 配置中做到这一点。

【问题讨论】:

    标签: nginx supervisord


    【解决方案1】:

    真正有趣的是,像将 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

    这在大多数情况下都有效,但并非总是如此。以下主管的网络功能将失败:

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

    2. 活尾不工作;但是有一个手动刷新的日志显示,它在程序名称的链接下工作。

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

    【讨论】:

      【解决方案2】:

      我可以简单地使用它:

      upstream supervisor {
        server 127.0.0.1:9001;
      }
      
      server {
        # ... 
      
        location /supervisor/ {
          proxy_pass  http://supervisor/;
        }
      }
      

      甚至可以在浏览器中使用或不使用 url 中的斜线结尾(即 http://example.com/supervisorhttp://example.com/supervisor/ 都有效)。 这对我来说是必须的!

      【讨论】:

        猜你喜欢
        • 2020-04-22
        • 1970-01-01
        • 1970-01-01
        • 2015-06-04
        • 1970-01-01
        • 1970-01-01
        • 2016-12-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多