2017-02-10 111 views
0

我有一个supervisord服务器上运行localhost:9001。 我正在尝试在localhost/supervisord处提供。Nginx的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 /图像正确加载到浏览器:

Assets loaded

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

Stylesheet not loaded

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

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

我该如何解决这个错误?

我想过动态地重写静态文件的MIME类型,但我不是nginx的专家,也不知道如何从nginx配置中做到这一点。

回答

1

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

反正这是我做的就是反向代理与应用程序,其中root不能修改工作,就像导师:

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

      location/{ 

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

应用端请求将达到主要终点,但随后的nginx会再引导他们到/主管EP

这在大多数情况下,但不是always.The以下上司的网络功能将失败:

  1. 越来越操作确认 - 您可以启动/停止服务,但结果页面将无法加载;只需到/主管EP检查结果

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

无论如何,这部分支持对我来说很好,你可能会觉得它也很有用。