Could not connect to the api server while running behind NGINX

I am trying to host Dockerized Baserow on my server behind Nginx.

Getting this Error: could not connect to the api server
while trying to signup

Note
I have listed one configuration details including my docker comands but I almost have tried all methods listed on Baserow documentation.
Some resulted in 502 error, some in Website not found etc

Here is my current configuration details that is atleast showing me Some Signup UI:

Server: 22.04 LTS
Server Management: CloudPanel
Reverse Proxy: NGINIX

My 80 and 443 ports are being handled by NGINX so they are not free at all.

Here is my docker-compose.yml

# This is the recommended way of running Baserow using docker-compose for most users.
# See https://baserow.io/docs/installation%2Finstall-with-docker for more details.
version: "3.4"
services:
  baserow:
    container_name: baserow
    image: baserow/baserow:1.24.2
    environment:
      BASEROW_PUBLIC_URL: 'https://baserow.amigrate.com:3006'
    ports:
      - "3005:80"
      
    volumes:
      - baserow_data:/baserow/data
volumes:
  baserow_data:

Here is my NGINX configuration

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name baserow.amigrate.com;
  {{root}}

  {{nginx_access_log}}
  {{nginx_error_log}}

  if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
  }

  location @reverse_proxy {
    proxy_pass {{reverse_proxy_url}};
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass_request_headers on;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout 900;
    proxy_send_timeout 900;
    proxy_read_timeout 900;
    proxy_buffer_size 128k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
  }

  {{settings}}

  add_header Cache-Control no-transform;

  index index.html;

  location ^~ /.well-known {
    auth_basic off;
    allow all;
    try_files $uri @reverse_proxy;
  }

  location / {
    try_files $uri @reverse_proxy;
  }
}

Reverse Proxy URL:

http://baserow.amigrate.com:3005

I tried almost very method provided in documentation.
Nothing is working for me!!

Is not there any step by step guide to host Baserow behind nginx on non standard custom declared ports

Hi @ziach, there is some documentation available here: Installing Baserow behind Nginx // Baserow. It’s important that the BASEROW_PUBLIC_URL matches the exact URL you’re visiting in your browser. If NGINX is listening on port 80 and 443, then the BASEROW_PUBLIC_URL must be equal to https://baserow.amigrate.com because that’s the URL you’re visiting in your browser.

Would you be able to get your environment back into a state where it shows the registration form, and then share the HTTP network response when you get the Getting this Error: could not connect to the api server error?

Hi!

One thing I’ve noticed you may want to check. You wrote that you’re using http://baserow.amigrate.com:3005 as the upstream address.

This seems to be a public address and my guess is nginx may not be able to connect to it (hence 502 error). If that’s the case, you should set your upstream address to docker compose’s host (if you’re running nginx and compose on the same host, http://localhost:3005).

Hi @bram and @cezary I have tried all the mentioned methods but nothing is working in my case.
Here is a brief intro to my setup:

My Nginx is listening at 80 and 443.
I don’t wanna use Caddy.

So my intention is to use NGINX as a reverse proxy.

I used docker-compose-no-caddy.yml file with one modification.

in this file We have following default value:

web-frontend:
    image: baserow/web-frontend:1.24.2
    restart: unless-stopped
    ports:
      - "${HOST_PUBLISH_IP:-127.0.0.1}:3000:3000"

But my port 3000 is also taken So I changed it to

"${HOST_PUBLISH_IP:-127.0.0.1}:3001:3001"

And Here is my .env file

SECRET_KEY=Strong_Secret_key
DATABASE_PASSWORD=Random_DB_Password
REDIS_PASSWORD=Redis_DB_Password


BASEROW_PUBLIC_URL=https://baserow.xyz.com:8003 \

WEB_FRONTEND_PORT=8003
WEB_FRONTEND_SSL_PORT= \

I append 8003 to my Public URL because I am running it on a non standard port.

and here is my Reverse Proxy URL from NGINX:

https://baserow.xyz.com:8003

Can you please spot anything that I am doing wrong.

I am getting Error 502.

Hi @ziach!

From your description I conclude that your setup looks like this (ports may not be exactly right):

But because you’re using wrong proxy_pass value in Nginx, it can’t connect to the containers to proxy the traffic, hence HTTP 502 error.

Assuming you’re running Docker on the same host as you’re running nginx, for all-in-one setup you should set it to http://localhost:EXPOSED_PORT, to have the setup like this:

Sorry, the first image is wrong. My understanding of your setup is as below (again, ports may be not exact - they are for illustrative purpose only):

Hi @cezary !
Thank you for your valuable suggestions.
I tried different setups as per your recommendations but still nothing is working in my case.

I am trying from the last week and after trying almost every possible way according to documentation I did not succeed to make it work even for the single time.

I tried Nocodb, I was able to set it up very easily while I am stuck with Baserow and I am assuming that Baserow can provide more value and options for my team.

Now in order to make everything super simple I run my Baserow via this command:

docker run \
  -d \
  --name baserow \
  -e BASEROW_PUBLIC_URL=http://127.0.0.1:3001 \
  -v baserow_data:/baserow/data \
  -p 3001:80 \
  --restart unless-stopped \
  baserow/baserow:1.24.2

and according to my docker logs everything is running properly.

But still I am not able to access my dashboard.

I am receiving this:

Site not found
The page you are looking for has not been found. This might be because URL is incorrect or that you don’t have permission to view this page.

Here is my assumption:

My container is running at http://127.0.0.1:3001
so it must at least be accessible via http://m_yIp:3001

But I am receiving site not found error.

My docker logs:

 [STARTUP][2024-04-16 11:24:46] No DATABASE_HOST or DATABASE_URL provided, using embedded postgres.
 [STARTUP][2024-04-16 11:24:46] Using embedded baserow redis as no REDIS_HOST or REDIS_URL provided.
 [STARTUP][2024-04-16 11:24:46] Creating REDIS_PASSWORD secret in /baserow/data/.redispass
 [STARTUP][2024-04-16 11:24:46] Importing REDIS_PASSWORD secret from /baserow/data/.redispass
 [STARTUP][2024-04-16 11:24:46] Creating SECRET_KEY secret in /baserow/data/.secret
 [STARTUP][2024-04-16 11:24:46] Importing SECRET_KEY secret from /baserow/data/.secret
 [STARTUP][2024-04-16 11:24:46] Creating BASEROW_JWT_SIGNING_KEY secret in /baserow/data/.jwt_signing_key
 [STARTUP][2024-04-16 11:24:46] Importing BASEROW_JWT_SIGNING_KEY secret from /baserow/data/.jwt_signing_key
 [STARTUP][2024-04-16 11:24:46] Creating DATABASE_PASSWORD secret in /baserow/data/.pgpass
 [STARTUP][2024-04-16 11:24:46] Importing DATABASE_PASSWORD secret from /baserow/data/.pgpass

=========================================================================================

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—    β–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘    β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ•— β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•  β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ•”β•
β•šβ•β•β•β•β•β• β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•β•šβ•β•  β•šβ•β• β•šβ•β•β•β•β•β•  β•šβ•β•β•β•šβ•β•β•

Version 1.24.2

=========================================================================================

[STARTUP][2024-04-16 11:24:46] Running setup of embedded baserow database.
 [POSTGRES_INIT][2024-04-16 11:24:49] Becoming postgres superuser to run setup SQL commands:
 [POSTGRES_INIT][2024-04-16 11:24:49] CREATE DATABASE
 [POSTGRES_INIT][2024-04-16 11:24:49] CREATE ROLE
 [POSTGRES_INIT][2024-04-16 11:24:49] GRANT
 [POSTGRES_INIT][2024-04-16 11:24:49] ALTER DATABASE
 [POSTGRES_INIT][2024-04-16 11:24:49]
 [POSTGRES_INIT][2024-04-16 11:24:49] PostgreSQL init process complete; ready for start up.
 [POSTGRES_INIT][2024-04-16 11:24:49]
 [STARTUP][2024-04-16 11:24:49] Starting Baserow using addresses http://127.0.0.1:3001, if any are https automatically Caddy will attempt to setup HTTPS automatically.
 [STARTUP][2024-04-16 11:24:49] Starting all Baserow processes:

Your instance is available from http://127.0.0.1:3001 only (literally, this address needs to be typed into browser’s url bar) - this is the value you’ve provided with BASEROW_PUBLIC_URL env variable.

You need:

  • set BASEROW_PUBLIC_URL env variable to http://baserow.xyz.com:$NGINX_PORT for Baserow containers. This value should point to Nginx endpoint. $NGINX_PORT is a non-standard port of Nginx (if you’re using such, and it seems you want to do that in this case).
  • set proxy_pass addresses to http://localhost:$DOCKER_EXPOSED_PORT in nginx configuration (assuming docker is running on the same host as nginx). $DOCKER_EXPOSED_PORT should be a port exposed by an appropriate container.

Those are two separate aspects of such deployment that need to be set up properly.

1 Like

@cezary
I make it work.

Note: In both cases my proxy url was:

http://baserow.xyz.com:3001

Actually In documentation it is written that for a non standard port docker command will be like:

docker run \
  -d \
  --name baserow \
  -e BASEROW_PUBLIC_URL=https://baserow.xyz.com:3001 \
  -v baserow_data:/baserow/data \
  -p 3001:80 \
  --restart unless-stopped \
  baserow/baserow:1.24.2

But Now I made one modification in this command that make everything work

docker run \
  -d \
  --name baserow \
  -e BASEROW_PUBLIC_URL=https://baserow.xyz.com \
  -v baserow_data:/baserow/data \
  -p 3001:80 \
  --restart unless-stopped \
  baserow/baserow:1.24.2

Difference: We don’t have to mention port in BASEROW_PUBLIC_URL even if we are running on a non standard port.

It’s working in case of NGINX as reverse proxy.
Not tested for other scenarios like Apache and any other configurations.