Bad Gateway Errors when connecting Data Sources, e.g. InfluxDB

CMD screenshot of me accessing influxdb using CLI interface in the Windows Command Line Prompt

access_influxdb_using_cli

Are you able to access the database from a command line running inside the grafana container? I don’t use docker with grafana but I do know that it is necessary to allow the container access to localhost for that to work. Have you tried using the ip address of the machine rather than localhost? Also check that works from the command line in case influx is only accessible via localhost.

[Edit] If you don’t need to enter a user/pwd to access the db in the command line they you should not have basic auth enabled or provide a user/pwd

1 Like

I replaced “localhost” with my IP address and it worked. Maybe that could work for you too.

1 Like

I have tried to reply on the forum, but because i’m a new user i cannot. Yes thankyou i replaced the localhost with IP address and it worked right away.

Maybe you can reply on the forum?

Regards

Glad that it worked.

Thank you.

http://localhost:8086 works - you just have to physically type it in the address, as what is shown is an example, and does not default to this

1 Like

I inspected my Grafana docker container using the command docker inspect {containter_name}. I then replaced localhost with the ip address listed under networks section (for example, “IPAddress”: “172.31.0.2”) and it worked for me.

Thank you for this fix! This is not good UI practice. I figured that if something was typed into the textbox, it was the actual value being used. I never thought to type in what was “already” typed in.

The e.g. text should be below or next to the textbox.

image

Hi Team,

I’m facing the same issue of bad gateway 502 and have tried all the above steps
can you please check? I will paste the snapshot of my grafana configuration here


Hi Graffana team,

I am facing the same issue. We had graffana version 5.2.0 it was working fine then we upgraded to other 7.5.5, 8.1.5 and seen this 502 bad gateway error then we have switched back to 5.2.0 but still I am seeing the same error. Below is my configuration

The issue is due to the missing / on the admin interface default value for HTTP host URL field
by default it is set to
http://localhost:8086
you have to change it with
http://localhost:8086/ (do not forget the trailing slash)

it resolved the issue for me

@cfilippe appending / does not resolve my issue, I have tried both with http://localhost:8086/ and also http://influx-influxdb:8086/

Need help on this ASAP

If you are using Influxdb in a container, replace localhost with the container name(same name in the docker compose). It solved the problem for me


I also encountered this problem when I used ‘http://localhost:9090/’, the default port, to solve this problem. But my data is still not shown, maybe the template does not support Windows.

“Bad Gateway” errors typically mean there is an error between the “Client” (here, typically Grafana) and the “Backend Server” (the data source you’re trying to use) and that the Backend server is not responding correctly.

Recommendations:

  • Ensure InfluxDB (or other datasource) is installed and running locally on your machine.
  • Verify that the service is accessible via the correct URL and port (e.g. for InfluxDB default is http://localhost:8086).
  • Use the InfluxDB (or other) command line tools or curl to confirm connectivity to the service. If this won’t work correctly, then there is no chance to get the data source configured correctly.
  • Check that the Grafana data source configuration matches the InfluxDB setup, including URL, port, and authentication details.
  • If using Docker, ensure that the container network settings allow communication between Grafana and InfluxDB - this can be tricky depending on how docker or docker-compose is set up. (E.g. using container-name as the host, or using host.docker.internal)
  • If you have additional issues, when raising questions about this, it is critical that you post your configuration for people to help you.

Summary:
The thread discusses issues with connecting Grafana to InfluxDB and other data sources, particularly InfluxDB on Windows systems. The key of the discussion is in properly configuring the underlying data source, particularly when running in Docker, and troubleshooting that it is accessible first before attempting to connect it as a data source

References