arachnys / cabot

Self-hosted, easily-deployable monitoring and alerts service - like a lightweight PagerDuty
MIT License
5.6k stars 594 forks source link

/graphite endpoint doesn't work behind reverse proxy (url path) #391

Open mikeder opened 8 years ago

mikeder commented 8 years ago

I am trying to get multiple Cabot instances working behind a reverse proxy and I'm running into an issue now where requests to /graphite return a 404 because the URL_PREFIX is not included in the request.

Would it be possible to include the URL_PREFIX, if defined, in these requests?

My reverse proxy config looks like this:

 # Subdir Config
        location /subdir/ {
                proxy_pass  http://host.domain.com:8080/subdir/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect    off;
        }
        location /subdir/static/ {
                proxy_pass  http://host.domain.com:8080/static/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect    off;
        }

With this config I can't figure out how to catch and rewrite the /graphite endpoint as it will need to redirect to different sub directories. The easiest approach that I can think of would be to include the URL_PREFIX here - https://github.com/arachnys/cabot/blame/master/cabot/templates/cabotapp/statuscheck_form.html#L35

EDIT: The /graphite endpoint works fine on when the reverse proxy is listening on a subdomain. This is only an issue when trying to proxy pass to a path.

mikeder commented 8 years ago

For now, I've found a work around in NGINX that seems to work. I've added the following block to my config to handle these types of requests, it will need a separate 'if' block for each upstream/backend but its at least working.

        # Subdir Config
        location /app1/ {
                proxy_pass  http://host.domain.com:8080/app1/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect    off;
        }
        location /app1/static/ {
                proxy_pass  http://host.domain.com:8080/static/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect    off;
        }

        # This section will need to be updated for each additional webapp. The $send_to variable
        # should include the port that the app proxy is listening on and the URL_PREFIX for that app
        location /graphite/ {
                if ($http_referer ~* (app1)) {
                        set $send_to "8080/app1";
                }
                proxy_pass http://host.domain.com:$send_to/graphite/?$args;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_redirect    off;
        }