influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

influxDB2.0 alpha - http custom base path

Open steverweber opened this issue 5 years ago • 75 comments

Trying to serve influxdb v2.0alpha through nginx proxy because I need to run multiple websites on the same host while admins only allow one port to be open 443.

https://dnsname/influxdb2

influxdb http page is referencing the root url path to load the site .js also noticed <base href="/"> is the url root.

is their some header that I should be passing upstream to influxdb so it knows to use a different basepath? or could an option be added to influxd so the base path can be custom?

Thanks!

<!doctype html>
<html>
<head><meta http-equiv="Content-type" content="text/html;charset=utf-8width=device-width,initial-scale=1" name="viewport"><title>InfluxDB 2.0</title><base href="/">
<link rel="shortcut icon" href="/favicon.ico"></head>
<body><div id="react-root" data-basepath=""></div>
<!-- want this to be something like: influxdb2/a02e0ac4f4.js  or a02e0ac4f4.js and use base href="/influxdb2/" -->
<script src="/a02e0ac4f4.js"></script>
</body></html>

steverweber avatar Nov 01 '19 17:11 steverweber

looking at the code git checkout v2.0.0-alpha.19 i see some env vars... but setting them didn't help.

systemd...

Environment="STATIC_PREFIX=/influxdb2/"
Environment="API_PREFIX=/influxdb2/"
Environment="BASE_PATH=/influxdb2/"
Environment="API_BASE_PATH=/influxdb2/"
ExecStart=/srv/influxd

also seems that the option is in Chronograf looking at the readme

./chronograf/README.md:Change the default root path of the Chronograf server with the `--basepath`

perhaps this should be made available on influxd --basepath=/influxdb2/

steverweber avatar Nov 01 '19 18:11 steverweber

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 30 '20 19:01 stale[bot]

please provide some feedback before closing. Thanks.

steverweber avatar Jan 30 '20 19:01 steverweber

For the base path parameters.. those are for configuring the frontend during compilation to allow it to be run behind a proxy, so they're already baked in by the time the image is pushed to the registry. Here's an example dockerfile that I use when i want to expose the frontend on a different url, passing those environment variables as build ARGs:

FROM ubuntu:bionic AS base

RUN apt-get update -y && \
    apt-get install -y \
        nginx \
        build-essential \
        curl \
        git

FROM base AS repo
WORKDIR /repo

ARG STATIC_DIRECTORY
ARG BASE_PATH
ARG API_BASE_PATH

ENV PATH="/node/bin:${PATH}"
RUN mkdir /node && \
    curl -sL https://git.io/n-install | N_PREFIX=/node bash -s -- -q && \
    npm i -g yarn

RUN git clone git://github.com/influxdata/influxdb.git && \
    cd ./influxdb

WORKDIR /repo/influxdb/ui

# these are all run together as docker's caching mechanism
# makes big steps like yarn install expensive
RUN yarn install --production=false && \
    yarn generate && \
    INFLUXDB_SHA=remote $(npm bin)/webpack --config ./webpack.prod.ts --bail && \
    rm -rf ./node_modules

FROM base AS deploy
WORKDIR /repo
COPY --from=repo /repo/influxdb/ui/build /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/nginx.conf
RUN useradd --no-create-home nginx

CMD ["nginx", "-g", "daemon off;"]

with just a simple nginx config in ./nginx.conf that hosts the files in `/usr/share/nginx/html' as your desired path:

  server {
    listen [::]:80;
    listen 80;

    server_name _;

    # Path for static files
    root /usr/share/nginx/html;

    location / {
      try_files $uri /index.html;
    }
  }

drdelambre avatar Feb 20 '20 16:02 drdelambre

Rebuilding the UI with a variable seems not to be a solution. Setting an environment variable to override the base href and/or taking this from the request X-Forwarded-Prefix would be necessary to run influxdb2 behind a proxy with a subdirectory.

kwinkel avatar Aug 26 '20 22:08 kwinkel

Having a similar issue. I did follow https://gist.github.com/mvadu/5fbb7f5676ce31f2b1e6 from an older version to try setting up things. However, it only loads the login page at http://mydomain.com/influxdb/, which doesn't work.

My setup is: (relevant parts only) nginx.conf:

upstream influxdb {
		server localhost:8086;
		keepalive 10;
	}
	#check the referer to identify requests originated by Influx UI
	map $http_referer $proxyloc {	
		~*influx influxdb;
	}
	
	#Influx Web API end points
	map $request_uri $backend {	
		~*query influxdb;
		~*write influxdb;
		~*ping  influxdb;
	}

server conf:

[...]
location / {
		if ($backend) {
			return 302 /$backend/$request_uri;
		}
	
		if ($proxyloc) {
			return 302 /$proxyloc/$uri;
		}
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	
	location /influxdb/ {
			
		proxy_pass	   http://localhost:8086/;
		proxy_set_header   Host			$http_host;
		proxy_set_header   X-Real-IP		$remote_addr;
		proxy_set_header   X-Forwarded-For	$proxy_add_x_forwarded_for;
	}
[...]

As said, my current configuration seems to load the login page fine, but it's unfunctional as it doesn't allow me access it.

Note: I use the docker container for influxdb2.0 beta from https://quay.io/repository/influxdb/influxdb?tag=2.0.0-beta&tab=tags

CLKBlu3 avatar Sep 23 '20 14:09 CLKBlu3

Similar issue! Grrrrrr!

cappelaere avatar Nov 27 '20 13:11 cappelaere

Is there any progress on this? I would really like to put Influx 2 OSS behind a reversproxy.

lephisto avatar Jan 10 '21 00:01 lephisto

Same happening here, can't reverse proxy Influx 2.0. Even after many hours trying with apache html proxy for rewriting urls I can't get it working.

nikosamus avatar Jan 13 '21 11:01 nikosamus

For people that had the same issue I did (commented a few months ago). We managed to make it work by using subdomains. So if you have a domain (we got our certs with Certbot), I can recommend trying this. We registered ours as mysubdomain.mydomain.com (sample name, obviously) This way, all the paths should work, since we do not have a "custom" base path as we used to, but instead have a new "root" path that can match influxdb's ones without messing our configuration.

Sample nginx configuration:

server {
        server_name     mysubdomain.mydomain.com;

        location / {

                #access_log /var/log/nginx/influx-access.log influx buffer=1024 flush=5m;
                proxy_pass         http://localhost:xxxx/;
                proxy_set_header   Host                 $http_host;
                proxy_set_header   X-Real-IP            $remote_addr;
                proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysubdomain.mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysubdomain.mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
[...] # Other conf stuff

CLKBlu3 avatar Jan 13 '21 11:01 CLKBlu3

seems the only solution to date is recompiling the source code because the path is baked in. workarounds:

  • give-up and use a different hostname or a subdomain.
  • write some hacky nginx config that might work? and then might break after some updates to influxdb (https://gist.github.com/mvadu/5fbb7f5676ce31f2b1e6)

Guess i'll just continue to ignore the influx UI and use the CLI for the odd admin task. Grafana runing under a custom base url is working out well for viewing data and setting alerts.

steverweber avatar Jan 16 '21 15:01 steverweber

Having the same issue... I just spent about 4 hours on it before finding this thread... For now I think I'll have to go with subdomain as no matter how I mess with the nginx config even if I get some web pages to load, some network requests just won't...

YassineElbouchaibi avatar Feb 24 '21 04:02 YassineElbouchaibi

Chiming in to put a bit more weight onto this issue. I've also just stumbled across this issue when trying to find a solution for the past hours. I wonder why this isn't troublesome for more people, using a reverse proxy with a custom subpath seems to be kind of a standard.

monsdar avatar Mar 10 '21 19:03 monsdar

Spend few days on this issue. So far it seems unresolvable without using subdomain for host based filtering in Ingress.

I needed to use InfluxDB UI behing nginx reverse proxy. With only one ingress-controller for the whole cluster. Turns out path based routing is possible with rewrite-target annotation in Ingress resource. But the Influx UI does not display at all. What ultimately cancelled any effort to use Ingress was that <base href="/"> thing, which doused any effort for us to use Ingress.

We would welcome any customization of base_href path, possibly via helm chart as we're using that for deployment.

One option could be to separate INFLUXD_HTTP_BIND_ADDRESS responsibility to server as address to InfluxDB API. And some other ENV_VAR would be responsible for settings path for Influx UI. It would have to be customizable via helm chart as well.

ondrej-ivanko avatar Mar 15 '21 15:03 ondrej-ivanko

Having the same issue, spent almost a day finding a solution with trying out different configs. finally, I am here :)

Turns out path based routing is possible with rewrite-target annotation in Ingress resource. But the Influx UI does not display at all.

@ondrej-ivanko I hope what you mean is, you could access the influx DB API endpoints(write and query) using the path-based routing approach. but no luck in accessing UI.

If that's true can you share the working config with rewrite-target annotation?

gvasanka avatar May 19 '21 11:05 gvasanka

@gvasanka I can't confirm that accessing API endpoints with rewrite-target annotation will work, as I haven't tried it. I don't see any reason, why it shouldn't work though.

If that's true can you share the working config with rewrite-target annotation?

Our company decided to abandon the effort to use Ingress controller. We just use port-forwarding of Influx pod for accessing UI.

ondrej-ivanko avatar May 20 '21 18:05 ondrej-ivanko

@ondrej-ivanko Thank you very much for your answer.

I was able to get access to influxDb 2 API with the below Ingress config. Posting it here for other's usage in case somebody struggling.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: influx-ingress-test
spec:
  rules:
  -  http:
      paths:
      - backend:
          serviceName: influxdb-release
          servicePort: 8086
        path: /influx(/|$)(.*)

But still no luck in getting access to the web.

gvasanka avatar May 21 '21 11:05 gvasanka

How is this not receiving more attention? Please can we get acknowledgement of the issue and get ENV access to set the base path like grafana has or appending to request url like even simple containers like adminer has. Apologies if I sound crass but having this hardcoded in is ridiculous. Running behind a reverse proxy nginx is something many people do and having to setup a subdomain just to workaround a HARDCODED base url is really silly.

Please try and give us some real commitment on this guys!

ecospecifier avatar Jun 21 '21 09:06 ecospecifier

I have a similar issue!

RavilN avatar Jun 21 '21 21:06 RavilN

Would like to also add my complaint to this thread. Grafana has a root_url parameter you can set in the config file. As far as I can tell, that is not the case with InfluxDB. Very frustrating that there appears to be no way for it to reside behind a reverse proxy without a subdomain.

jjriggs avatar Jun 26 '21 22:06 jjriggs

I would also need this feature, as i dont want to use a second subdomain for this.

ingaa85 avatar Jun 29 '21 08:06 ingaa85

From the commit that updates the UI version, it appears the UI releases are downloaded at build time and get bundled into the final go build. FYI: https://github.com/influxdata/influxdb/pull/21564/files

In that UI release bundle, <base href="/"> is already set. I think we should open a mirrored issue at the UI repo too.

UnKnoWn-Consortium avatar Jul 07 '21 22:07 UnKnoWn-Consortium

Having the same problem here, really thought it would be a simple setting to change when I started this.

Would love to see this updated, has anyone had any luck ?

TravisDuck999 avatar Jul 08 '21 18:07 TravisDuck999

Expressing my interest. I don't want to have to rebuild, and I don't want to use subdomains. Given Grafana has this feature and is commonly a part of the stack, I would hope that Influx soon has the same functionality.

mitchellkingsley avatar Jul 23 '21 18:07 mitchellkingsley

any update on this? :(

Keviinplz avatar Jul 27 '21 01:07 Keviinplz

Also checking back to see if there is any update on this, seems not.

ecospecifier avatar Jul 28 '21 10:07 ecospecifier

Just stumbled upon this problem too. Hopefully this will be addressed soon.

thomas725 avatar Aug 08 '21 16:08 thomas725

Just spent one day trying to make this work and ended here.

+1 for this custom param !

cavepopo avatar Aug 13 '21 07:08 cavepopo

+1

nbejansen avatar Sep 02 '21 07:09 nbejansen

Still a problem and I am still hopeful for a solution. Wanted to also add that Grafana supports proxy auth and it would be nice if influx2.0 could be setup for SSO via a tool like vouch proxy.

mattp0 avatar Sep 18 '21 00:09 mattp0

+1

h3po avatar Sep 18 '21 18:09 h3po