junegunn / redis-stat

(UNMAINTAINED) A real-time Redis monitoring tool
MIT License
2.02k stars 339 forks source link

Proxying redis-stat (with nginx) fails #56

Closed mmattel closed 7 years ago

mmattel commented 7 years ago

Ubuntu 16.04 Having other services proxied wih nginx successfully, it fails with redis-stat.

sudo redis-stat --server --daemon

Accessing via http(s)://domain/redis shows the following screen (proxied setup), but no content: image

Doing the same but accessing direct (http://server:63790), without nginx and proxying, works.

Example logs entries:

access log: "GET /js/site.js HTTP/2.0" 404 210 "https://xxxx/redis/"

error log: open() "/var/www/xxxx/js/site.js" failed (2: No such file or directory), request: "GET /js/site.js HTTP/2.0"

It tries to access files locally instead of proxying them

Here is the corresponding config. As said, other apps proxied work like a charm

        location /redis/ {
                # proxy to redis-stat
                proxy_buffering    off;
                proxy_set_header   Host $http_host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_http_version 1.1;
                proxy_pass         http://127.0.0.1:63790/;
        }

Tried to play with the nginx settings around, but it always ends up with the error messages described above.

junegunn commented 7 years ago

Thanks for the heads up. Sorry that I don't have enough time to maintain this project at the moment. redis-stat web server is just a sinatra app, I don't think there's anything special about it. So you might want to test if it works well with a simple sinatra app running on thin.

mmattel commented 7 years ago

@junegunn I found the root cause and after changing it, it worked for both, direct web access and for proxying (valid for any webserver)!

In file: redis-stat/lib/redis-stat/server/views/index.erb

old: path is web root-relative

...
    <title>redis-stat</title>
    <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/jqplot/jquery.jqplot.min.css" rel="stylesheet"/>
    <link href="/select2/select2.css" rel="stylesheet"/>
    <link href="/select2/select2-bootstrap.css" rel="stylesheet"/>
    <link href="/css/site.css" rel="stylesheet"/>
    <script type="text/javascript" src="/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="/jqplot/jquery.jqplot.min.js"></script>
    <script type="text/javascript" src="/jqplot/jqplot.canvasTextRenderer.min.js"></script>
    <script type="text/javascript" src="/jqplot/jqplot.canvasAxisLabelRenderer.min.js"></script>
    <script type="text/javascript" src="/jqplot/jqplot.canvasAxisTickRenderer.min.js"></script>
    <script type="text/javascript" src="/select2/select2.min.js"></script>
    <script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/site.js"></script>
...
        // TODO Check (typeof(EventSource) !== "undefined")

        var source = new EventSource("/pull")

new: pls see the dot before the slash making the path web root-relative independent

...
    <title>redis-stat</title>
    <link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="./jqplot/jquery.jqplot.min.css" rel="stylesheet"/>
    <link href="./select2/select2.css" rel="stylesheet"/>
    <link href="./select2/select2-bootstrap.css" rel="stylesheet"/>
    <link href="./css/site.css" rel="stylesheet"/>
    <script type="text/javascript" src="./jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="./jqplot/jquery.jqplot.min.js"></script>
    <script type="text/javascript" src="./jqplot/jqplot.canvasTextRenderer.min.js"></script>
    <script type="text/javascript" src="./jqplot/jqplot.canvasAxisLabelRenderer.min.js"></script>
    <script type="text/javascript" src="./jqplot/jqplot.canvasAxisTickRenderer.min.js"></script>
    <script type="text/javascript" src="./select2/select2.min.js"></script>
    <script type="text/javascript" src="./bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="./js/site.js"></script>
...
        // TODO Check (typeof(EventSource) !== "undefined")

        var source = new EventSource("./pull")

Difference:

  1. Web root-relative: my-domain-webroot-path/redis-stuff
  2. Web root-relative independent: redis-stuff

Proxying 1 can not work while 2 does.

Would be great if you could incooperate and merge it.

BTW: I have a sample config for nginx to proxy it, and a script example for Ubuntu to create a standard start/stop environment inclunding upstart. If interested - where to put it to? (I could add these to this issue and you could take it and merge it in your readme)

junegunn commented 7 years ago

Thanks for looking into it. Yeah, a script for setting up a testing environment would be nice.

A couple questions:

  1. We can simply remove the leading /, right? (instead of prepending .)
    • e.g. <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
  2. If so, what should we do with line 23?
    • <a class="brand" href="/">redis-stat</a>
mmattel commented 7 years ago

Thanks for looking into it. Yeah, a script for setting up a testing environment would be nice.

58

mmattel commented 7 years ago

ad 1 yes, you are right, just remove / http://webmasters.stackexchange.com/questions/56573/relative-link-to-a-subfolder

The part ./ is removed from the start of a URL as part of URL resolution as defined in STD 66. 
This has nothing to do with folders or files; it is just string manipulation dictated by generic 
URL specifications. Thus, for example, the URLs picture1.jpg and ./picture1.jpg have identical 
meaning: they resolve to the same absolute URL.

ad 2 http://stackoverflow.com/questions/9221872/link-practice-without-in-the-beginning-of-href

<a class="brand" href="/">redis-stat</a> -> <a class="brand" href="./">redis-stat</a>

It is not good practise to use subpage-1 urls exactly because of redirections you might 
implement later on. If you insist on working in a folder, you can use ./subpage-1 and 
./ for the home link.

I have tested it and it works. When you proxy to access redis-stat from a subfolder, the href link resolved must be the complete url like domain/redis-status. Without ./ you end up in domain (without redis-status subfolder in the URI) which is a different location.

junegunn commented 7 years ago

Thanks for digging those up. Would you be interested in sending me a PR?