2017-02-10 109 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. 活尾不工作;但是有一個手動刷新的日誌顯示,它與程序名稱鏈接。

無論如何,這部分支持對我來說很好,你可能會覺得它也很有用。