Chronograf: is there a way to set up a proxy server for chronograf

Created on 3 Feb 2017  路  25Comments  路  Source: influxdata/chronograf

I have installed chronograph on my centos machine, and the default setting is applied which listen on localhost and port 8888, i set up a proxy sever to redirect url /chronograf to http://xx.xx.xx:8888, but it is not working as all the links seems using absolute path like 'http://xxxxx/chronograf.css'

Most helpful comment

I managed to get this working behind nginx with chronograf. It was necessary for me to add the --prefix-routes switch in addition to the --basepath switch. Without that I was getting infinite redirects. This happens even when not using the proxy to hit the server.

Server is running on Centos and chronograf.service was modified to look like this:

[Unit]
Description=Open source monitoring and visualization UI for the entire TICK stack.
Documentation="https://www.influxdata.com/time-series-platform/chronograf/"
After=network-online.target

[Service]
User=chronograf
Group=chronograf
EnvironmentFile=-/etc/default/chronograf
#ExecStart=/usr/bin/chronograf --host 0.0.0.0 --port 8888 -b /var/lib/chronograf/chronograf-v1.db -c /usr/share/chronograf/canned
ExecStart=/usr/bin/chronograf --host 0.0.0.0 --port 8888 --basepath /chronograf --prefix-routes -b /var/lib/chronograf/chronograf-v1.db -c /usr/share/chronograf/canned
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target

and the location block in my nginx.conf file like this:

    # Chronograf reverse proxy
    location ^~ /chronograf/ {
      proxy_ignore_client_abort on;
      proxy_pass http://127.0.0.1:8888;
      proxy_set_header Host $host;
    }

Hope this is useful to anyone else wanting to set this up.

All 25 comments

Hi @jacy thanks for writing in! Yup, we have that feature. @timraymond just added that into our 1.2.0-beta1 release here: #814 and #819

The bottom line is that you either use an env var BASE_PATH or -basepath CLI options. Base path is a URL path prefix under which all chronograf routes will be mounted.

So, I think you'll want to do --basepath /chronograf or BASE_PATH=/chronograf

Let me know if it works for you!

Hi @goller
Thanks for your reply, my chronograf version is:
Chronograf 1.2.0~beta1 (git: 2dbddaf84a03514471ac02d112bf4d63953bdfcf)

I have tried env setting(export BASE_PATH=chronograf) and CLI(/usr/bin/chronograf --host 0.0.0.0 --port 8888 -b /var/lib/chronograf/chronograf-v1.db -c /usr/share/chronograf/canned -basepath chronograf), but it seems not working, did I do it the wrong way?

Hey @jacy, you did it just right. Would you put the chronograf logs into the issue? One thing we'll be able to see from the logs is if it is getting traffic or not.

Also, what URL are you using to get to the server? It should be http://server:8888/chronograf

@goller, after checked the log, it seems -basepath kinda override -b option, and it is now working using --basepath instead, thanks for your help, you saved my day.

Great @jacy, well, we had -basepath in the README. I've updated it to double dash here: https://github.com/influxdata/chronograf/pull/849

I'm also going to edit what I wrote in this issue to make sure it says double dash so others in the future get the right advice.

@goller Nice, thanks.

I actually now have another problem:

Currently my setting is --basepath chronograf

And front end proxy mapping:

http://proxy.come/chronograf/ -> http://my.chronograf.server.com:8888/

With base path chronograf, the service is able to add the context path "chronograf" in the beginning of every js/css source url, for example:

Ty @kinnarr I'm going to update what I wrote in this issue (again) for posterity.

yw

Apache 2.4.6 RHEL7.2 chronograf 1.3
Installed chronograf rpm, had to set environment variable BASE_PATH in the /etc/default/chronograf (systemd chronograf environment file) as such:

BASE_PATH=/chronograf

restarted the chronograf systemd service and it works.

apache reverse proxy (path) config:

ProxyPreserveHost On
ProxyPass /chronograf http://127.0.0.1:8888
ProxyPassReverse /chronograf http://127.0.0.1:8888

Thanks for the info!

@jmorin2126 thanks for writing this! Do you mind adding this information to chronograf's /docs directory? I'm sure others need this.

I managed to get this working behind nginx with chronograf. It was necessary for me to add the --prefix-routes switch in addition to the --basepath switch. Without that I was getting infinite redirects. This happens even when not using the proxy to hit the server.

Server is running on Centos and chronograf.service was modified to look like this:

[Unit]
Description=Open source monitoring and visualization UI for the entire TICK stack.
Documentation="https://www.influxdata.com/time-series-platform/chronograf/"
After=network-online.target

[Service]
User=chronograf
Group=chronograf
EnvironmentFile=-/etc/default/chronograf
#ExecStart=/usr/bin/chronograf --host 0.0.0.0 --port 8888 -b /var/lib/chronograf/chronograf-v1.db -c /usr/share/chronograf/canned
ExecStart=/usr/bin/chronograf --host 0.0.0.0 --port 8888 --basepath /chronograf --prefix-routes -b /var/lib/chronograf/chronograf-v1.db -c /usr/share/chronograf/canned
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target

and the location block in my nginx.conf file like this:

    # Chronograf reverse proxy
    location ^~ /chronograf/ {
      proxy_ignore_client_abort on;
      proxy_pass http://127.0.0.1:8888;
      proxy_set_header Host $host;
    }

Hope this is useful to anyone else wanting to set this up.

@medington thanks for writing in... I've been reviewing the basepath/prefix-routes code and I'm starting to understand how it works. My instinct is that the prefix-routes was some sort of workaround for bugs that were not solved.

So, eventually, I'm going to refactor the basepath/prefix-routes code to truly be just a single CLI option (--basepath). I'm hoping there is not a real need to have two CLI parameters.

When I finish that work, I'll add to this issue and let everyone know. Would love to get feedback on the refactor.

@goller Thanks for the info. I had spotted an error in the journalctl output for chronograf service logs that suggested I needed to use the --prefix-routes and sure enough that resolved the issue with the redirects and allowed the UI to work through nginx.

@goller unfortunately it looks like there is a regression in 1.4.1.1. I can't get chronograf to work via an apache reverse proxy no matter what I try :(

Direct connections work fine though.

Hi @binary0111 -- tracking this down now.

@lukevmorris Thanks! much appreciated :)

Works in 1.4.1.2!

Thanks for the heads up

@medington - This nginx.conf configuration does not seem to work 100% for me. My Chrome/Firefox & inspect get frozen when selecting a host from the host list and no graphs come to display. Do you have any idea? Thank you.

Here my repo: https://github.com/carlessanagustin/TICK-docker

@carlessanagustin Sorry, that's not something I can help you with.

CentOS 7 working config, just having /chronograf on the web server redirect to a localhost instance of chronograf.

edit /etc/default/chronograf:

BASE_PATH=/chronograf
HOST=127.0.0.1

The above makes chronograf listen on localhost. Validate by netstat -an | grep 8888 and you should see a tcp LISTEN socket on 127.0.0.1:8888.

# netstat -an | grep 8888
tcp        0      0 127.0.0.1:8888          0.0.0.0:*               LISTEN

Here's my Apache 2.4 config:

<Location "/chronograf">
  ProxyPass http://localhost:8888/chronograf
</Location>
ProxyPassReverse /chronograf http://localhost:8888/chronograf

In my case the above is in the VirtualHost directive of ssl.conf.

Hi, my setup is Ubuntu where chronograf is running on docker. GUI is via nginx. Works perfect. Thanks here for tips!

snippet from docker-compose.yml

chronograf:
image: chronograf:latest
container_name: chronograf
networks:
- monitor_net
ports:
- "8888:8888"
depends_on:
- influxdb
environment:
HOST: "0.0.0.0"
PORT: 8888
BASE_PATH: "/chronograf"
INFLUXDB_URL: "http://influxdb:8086"
INFLUXDB_USERNAME: ${INFLUXDB_ADMIN_USER}
INFLUXDB_PASSWORD: ${INFLUXDB_ADMIN_PASSWORD}
KAPACITOR_URL: "http://kapacitor:9093"
volumes:
- ./chronograf/data:/var/lib/chronograf
restart: always

snippet from nginx.conf

`

    location ^~ /chronograf/ {
        proxy_ignore_client_abort on;
        proxy_pass http://localhost:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mkarlesky picture mkarlesky  路  3Comments

jackzampolin picture jackzampolin  路  6Comments

karel-rehor picture karel-rehor  路  5Comments

121watts picture 121watts  路  6Comments

benschweizer picture benschweizer  路  5Comments