我有一个在 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
这在大多数情况下有效,但并非总是有效。以下主管的 Web 功能将失败:
获取操作确认 - 您可以启动/停止服务,但结果页面将无法加载;去/supervisor EP查看结果即可
实时尾部不起作用;但是,有一个带有手动刷新功能的日志显示,可以在带有程序名称的链接下运行。
无论如何,这种部分支持对我来说已经足够了,你可能会发现它也很有用。
关于Nginx 管理员配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42167959/