Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxying redis-stat (with nginx) fails #56

Closed
mmattel opened this issue Oct 4, 2016 · 6 comments
Closed

Proxying redis-stat (with nginx) fails #56

mmattel opened this issue Oct 4, 2016 · 6 comments

Comments

@mmattel
Copy link
Contributor

mmattel commented Oct 4, 2016

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
Copy link
Owner

junegunn commented Oct 4, 2016

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
Copy link
Contributor Author

mmattel commented Dec 6, 2016

@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
Copy link
Owner

junegunn commented Dec 7, 2016

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
Copy link
Contributor Author

mmattel commented Dec 7, 2016

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

#58

@mmattel
Copy link
Contributor Author

mmattel commented Dec 7, 2016

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
Copy link
Owner

junegunn commented Dec 8, 2016

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

mmattel added a commit to mmattel/redis-stat that referenced this issue Dec 9, 2016
Changes referencing issue junegunn#56
Intention: make redis-stat also working when proxying it.
Now you can configure your webserver to act as proxy and access redis-stat via ``your-domain/your-access-page``
This was not possible before due to web-root relative paths in index.erb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants