Skip to content

[FIX] Unable to host on internal ip and access admin panel #1114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
10 tasks
AndyG-0 opened this issue Feb 13, 2025 · 0 comments
Closed
10 tasks

[FIX] Unable to host on internal ip and access admin panel #1114

AndyG-0 opened this issue Feb 13, 2025 · 0 comments
Labels
fix Fix something that isn't working as expected

Comments

@AndyG-0
Copy link

AndyG-0 commented Feb 13, 2025

Describe the bug

I am trying to host Khoj on an internal nas for personal use. I'm using container manager from Synology and using the compose file from the repo to run with a few minor tweaks to make it compatible with Container manager. Mostly just how volume mappings work. I have set the environment variable for the admin email and password. The site comes up with the default account which is for anonymous access, however access admin does not work. My username and password is accepted because it does throw an error if it's a bad pass, however the admin login page just displays again. It's like it get lost after successful auth and it just sends back to the login. I have the khoj_domain also set to 192.168.60.190 which is the ip to my nas the port is still the default 42110. Note: I did try to create a local domain of nas.local and I set the khoj_domain to this but I still was getting csrf errors from Django.

To Reproduce

I don't know that the NAS is important here but try hosting on any local ip other than localhost and I'm assuming the login will do the same. Maybe it's just not possible to run this way.

Screenshots

If applicable, add screenshots to help explain your problem.

It's just the login screen again not sure screenshots are that useful. I can provide one if needed.

Platform

  • Server:
    • Cloud-Hosted (https://app.khoj.dev)
    • [ X] Self-Hosted Docker
    • Self-Hosted Python package
    • Self-Hosted source code
  • Client:
    • Obsidian
    • Emacs
    • Desktop app
    • [ X] Web browser
    • WhatsApp
  • OS:
    • [ X] Windows - windows client(browser)
    • macOS
    • [ X] Linux - nas is linux
    • Android
    • iOS

If self-hosted

  • Server Version [e.g. 1.0.1]: Using the latest images.

Additional context

Add any other context about the problem here.

Full docker compose:

services:
  database:
    image: ankane/pgvector
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres
    volumes:
      - /volume1/docker/khoj/khoj_db/:/var/lib/postgresql/data/
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 10s
      retries: 5
  sandbox:
    image: ghcr.io/khoj-ai/terrarium:latest
  server:
    depends_on:
      database:
        condition: service_healthy
    # Use the following line to use the latest version of khoj. Otherwise, it will build from source. Set this to ghcr.io/khoj-ai/khoj-cloud:latest if you want to use the prod image.
    image: ghcr.io/khoj-ai/khoj:latest
    # Uncomment the following line to build from source. This will take a few minutes. Comment the next two lines out if you want to use the official image.
    # build:
      # context: .
    ports:
      # If changing the local port (left hand side), no other changes required.
      # If changing the remote port (right hand side),
      #   change the port in the args in the build section,
      #   as well as the port in the command section to match
      - "42110:42110"
    extra_hosts:
      - "host.containers.internal:host-gateway"
    working_dir: /app
    volumes:
      - /volume1/docker/khoj/khoj_config:/root/.khoj/
      - /volume1/docker/khoj/khoj_models:/root/.cache/torch/sentence_transformers
      - /volume1/docker/khoj/khoj_models:/root/.cache/huggingface
    # Use 0.0.0.0 to explicitly set the host ip for the service on the container. https://pythonspeed.com/articles/docker-connection-refused/
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_HOST=database
      - POSTGRES_PORT=5432
      - KHOJ_DJANGO_SECRET_KEY=secret
      - KHOJ_DEBUG=True
      - [email protected]
      - KHOJ_ADMIN_PASSWORD=password
      # Default URL of Terrarium, the Python sandbox used by Khoj to run code. Its container is specified above
      - KHOJ_TERRARIUM_URL=http://sandbox:8080
      # Default URL of SearxNG, the default web search engine used by Khoj. Its container is specified above
      - KHOJ_SEARXNG_URL=http://192.168.60.190:8085
      # Uncomment line below to use with Ollama running on your local machine at localhost:11434.
      # Change URL to use with other OpenAI API compatible providers like VLLM, LMStudio etc.
      - OPENAI_BASE_URL=http://192.168.60.40:11434/v1/
      #
      # Uncomment appropriate lines below to use chat models by OpenAI, Anthropic, Google.
      # Ensure you set your provider specific API keys.
      # ---
      # - OPENAI_API_KEY=your_openai_api_key
      # - GEMINI_API_KEY=your_gemini_api_key
      # - ANTHROPIC_API_KEY=your_anthropic_api_key
      #
      # Uncomment appropriate lines below to enable web results with Khoj
      # Ensure you set your provider specific API keys.
      # ---
      # Free, Slower API. Does both web search and webpage read. Get API key from https://jina.ai/
      # - JINA_API_KEY=your_jina_api_key
      # Paid, Fast API. Only does web search. Get API key from https://serper.dev/
      # - SERPER_DEV_API_KEY=your_serper_dev_api_key
      # Paid, Fast, Open API. Only does webpage read. Get API key from https://firecrawl.dev/
      # - FIRECRAWL_API_KEY=your_firecrawl_api_key
      # Paid, Fast, Higher Read Success API. Only does webpage read. Get API key from https://olostep.com/
      # - OLOSTEP_API_KEY=your_olostep_api_key
      #
      # Uncomment the necessary lines below to make your instance publicly accessible.
      # Replace the KHOJ_DOMAIN with either your domain or IP address (no http/https prefix).
      # Proceed with caution, especially if you are using anonymous mode.
      # ---
      - KHOJ_NO_SSL=True
      - KHOJ_NO_HTTPS=True
      - KHOJ_DOMAIN=192.168.60.190
      # - KHOJ_DOMAIN=khoj.example.com
      # Uncomment the line below to disable telemetry.
      # Telemetry helps us prioritize feature development and understand how people are using Khoj
      # Read more at https://docs.khoj.dev/miscellaneous/telemetry
      - KHOJ_TELEMETRY_DISABLE=True
    # Comment out this line when you're using the official ghcr.io/khoj-ai/khoj-cloud:latest prod image.
    command: --host="0.0.0.0" --port=42110 -vvvvv --anonymous-mode

Only changes really to note from original are the way volumes work for synology. I also removed the Searxng as I already had one running. Then just the ip/urls for the vars.

@AndyG-0 AndyG-0 added the fix Fix something that isn't working as expected label Feb 13, 2025
debanjum added a commit that referenced this issue Feb 13, 2025
- Set KHOJ_ALLOWED_DOMAIN to the domain that Khoj is accessible on
  from the host machine. This can be the internal i.p or domain of the
  host machine.

  It can be used by your load balancer/reverse_proxy to access Khoj.
  For example, if the load balancer service is in the khoj docker
  network, KHOJ_DOMAIN will be `server' (i.e service name).

- Set KHOJ_DOMAIN to your externally accessible DOMAIN or I.P to avoid
  CSRF trusted origin or unset cookie issue when trying to access the
  khoj admin panel.

Resolves #1114
debanjum added a commit that referenced this issue Feb 14, 2025
- Set KHOJ_ALLOWED_DOMAIN to the domain that Khoj is accessible on
  from the host machine. This can be the internal i.p or domain of the
  host machine.

  It can be used by your load balancer/reverse_proxy to access Khoj.
  For example, if the load balancer service is in the khoj docker
  network, KHOJ_DOMAIN will be `server' (i.e service name).

- Set KHOJ_DOMAIN to your externally accessible DOMAIN or I.P to avoid
  CSRF trusted origin or unset cookie issue when trying to access the
  khoj admin panel.

Resolves #1114
debanjum added a commit that referenced this issue Feb 17, 2025
- Set KHOJ_ALLOWED_DOMAIN to the domain that Khoj is accessible on
  from the host machine. This can be the internal i.p or domain of the
  host machine.

  It can be used by your load balancer/reverse_proxy to access Khoj.
  For example, if the load balancer service is in the khoj docker
  network, KHOJ_DOMAIN will be `server' (i.e service name).

- Set KHOJ_DOMAIN to your externally accessible DOMAIN or I.P to avoid
  CSRF trusted origin or unset cookie issue when trying to access the
  khoj admin panel.

Resolves #1114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fix something that isn't working as expected
Projects
None yet
Development

No branches or pull requests

1 participant