How to configure API Nginx reverse proxy?

I wonder if someone can share a working template of NocoDB self-hosted instance (on Docker) in order to get API working.

It seems that /api/ path needs to have their own configuration for allowing connections and I didn’t found anything on Github or this forum related.

Thanks!

Hi @someguy

A simple setup with Nginx would look like following:

server {
        listen 80;
        server_name yourdomainname.tld;

        location / {
            proxy_pass http://localhost:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
}

Feel free to follow-up if you are still having issue

1 Like

Hey, thanks for your reply. I see the containers healthy but the API can’t be reached.

I tried curl -X GET "http://127.0.0.1:1111/api/v1/workspaces" -H "xc-token: MYTOKEN" -H "Content-Type: application/json" and using a working subdomain.

That’s the response:

{"msg":"Cannot GET /api/v1/workspaces"}

I changed the port on my docker-compose.yml file and tried NUXT_PUBLIC_NC_BACKEND_URL with the updated port.

It still not working but the app itself is fine. Can be related to Redis?

Any direction to follow?

As your local curl also doesn’t work I suspect something is wrong with your docker-compose settings.
Can you share me NocoDB part in file without confidential parts as well as container logs?

Also feel free to contact me via Discord if you need real-time help (you can either @ me on our server, or DM directly)

1 Like

Hey, thanks for your following up. Unfortunately I opt out Discord after a few issues the company had.

That’s my actual configuration, note that I’m running other services and I’m using Nginx (Reverse Proxy) + Cloudflare (DNS) to redirect the traffic from my domain assigned to NocoDB.

The app is working but not the API calls.

services: 
  nocodb: 
    container_name: nocodb-nauta
    depends_on: 
      root_db: 
        condition: service_healthy
    environment: 
      NC_DB: "pg://REDACTED:5432?u=REDACTED&p=REDACTED&d=root_db"
      NC_INVITE_ONLY_SIGNUP: true
      NC_DISABLE_TELE: true
      VIRTUAL_HOST: https://nocodb.mydomain.com
      NUXT_PUBLIC_NC_BACKEND_URL: https://nocodb.mydomain.com
#      NUXT_PUBLIC_NC_BACKEND_URL: http://127.0.0.1:8889
    image: "nocodb/nocodb:latest"
    ports: 
      - "127.0.0.1:8889:8080"
    restart: always
    volumes: 
      - "nc_data:/usr/app/data"
  root_db: 
    environment: 
      POSTGRES_DB: REDACTED
      POSTGRES_PASSWORD: REDACTED
      POSTGRES_USER: REDACTED
    healthcheck: 
      interval: 10s
      retries: 10
      test: "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""
      timeout: 2s
    image: postgres:16-bullseye
    restart: always
    volumes: 
      - "../../nocodb/data:/var/lib/postgresql/data"
volumes: 
  db_data: {}
  nc_data: {}

I commented a variable that I don’t understand I need to complete. And I’m using the same domain on NUXT_PUBLIC_NC_BACKEND_URL and VIRTUAL_HOST

Nginx configuration:

server {
        server_name nocodb.mydomain.com;
        listen 443 ssl http2;

    location / {

            proxy_pass http://127.0.0.1:8889;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
}

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

Any help will be appreciated!

Please refactor your env variables for NocoDB as following:

environment: 
      NC_DB: "pg://REDACTED:5432?u=REDACTED&p=REDACTED&d=root_db"
      NC_INVITE_ONLY_SIGNUP: true
      NC_DISABLE_TELE: true
      VIRTUAL_HOST: https://nocodb.mydomain.com
      NC_PUBLIC_URL: https://nocodb.mydomain.com

Removing NUXT_PUBLIC_NC_BACKEND_URL which doesn’t have effect on docker & using NC_PUBLIC_URL

Let me know if this works out for you

1 Like

With this configuration:

[Nest] 8 DEBUG [GlobalExceptionFilter] Cannot GET /api/v1/workspaces
[Nest] DEBUG [GlobalExceptionFilter] NotFoundException: Cannot GET /api/v1/workspaces
    at callback (/usr/src/app/node_modules/@nestjs/core/router/routes-resolver.js:77:19)

Can I debug more? What could be caussing this isue?

I think routing part is resolved as you’re getting requests to server.

While self hosting you get a single workspace so workspace apis are not available - this error is expected.

See https://meta-apis-v2.nocodb.com/ for further reference.

A good start would be /api/v2/meta/bases/