langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
45.3k stars 6.36k forks source link

Fail to Set Up Authorization of SearXNG base url #6942

Closed forhonourlx closed 1 month ago

forhonourlx commented 1 month ago

Self Checks

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When setting up Authorization of SearXNG base url, get error:

HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /?q=SearXNG&format=json&categories=general (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9a0636fa00>: Failed to establish a new connection: [Errno 111] Connection refused'))

image

settings.yml is already set to:

search:
  # remove format to deny access, use lower case.
  # formats: [html, csv, json, rss]
  formats:
    - html
    - json    # <-- add this line 

http://[localhost:8080/search?q=SearXNG&format=json&categories=general](http://localhost:8080/search?q=SearXNG&format=json&categories=general) and html web page could be access successfully. So, what's reason of this problem and how to slove? Could somebody kindly help? Thanks inadvance.

✔️ Expected Behavior

Success setting up Authorization of SearXNG base url

❌ Actual Behavior

HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /?q=SearXNG&format=json&categories=general (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9a0636fa00>: Failed to establish a new connection: [Errno 111] Connection refused'))
dosubot[bot] commented 1 month ago

Hey @forhonourlx! I'm here to help you with bugs, questions, and becoming a contributor. Let's get this issue sorted out together.

To resolve the "Failed to establish a new connection: [Errno 111] Connection refused" error when setting up the Authorization of the SearXNG base URL in your self-hosted Dify instance, ensure the following steps are correctly followed:

  1. Verify SearXNG is Running: Ensure that the SearXNG Docker container is running. You can check this by running:

    docker ps

    Look for a container with the name searxng or the image searxng/searxng.

  2. Correct Base URL: Make sure you are using the correct base URL. According to the documentation, it should be http://x.x.x.x:8080 where x.x.x.x is the IP address of the machine running the SearXNG Docker container. If you are running it locally, it might be http://127.0.0.1:8080 or http://localhost:8080.

  3. Network Configuration: Ensure that there are no network issues or firewall rules blocking the connection to the specified port (8080).

  4. Docker Command: Ensure you have used the correct Docker command to run SearXNG:

    docker run --rm \
               -d -p 8080:8080 \
               -v "${PWD}/searxng:/etc/searxng" \
               -e "BASE_URL=http://0.0.0.0:8080/" \
               -e "INSTANCE_NAME=searxng" \
               searxng/searxng
  5. Check SearXNG Logs: Check the logs of the SearXNG container for any errors that might indicate why it is not accepting connections:

    docker logs <container_id>
  6. Activate JSON Format: Ensure that the json format is activated in the settings.yml file located at ${PWD}/searxng/settings.yml:

    formats:
      - html
      - json    # <-- add this line 
  7. Integrate SearXNG in Dify: In Dify, go to Tools > SearXNG > Authenticate and fill in the access URL, for example: http://x.x.x.x:8080.

By following these steps, you should be able to resolve the connection issue and successfully authorize the SearXNG base URL in your Dify instance [1][2].

To continue talking to Dosu, mention @dosu.

hjlarry commented 1 month ago

you can enter the docker container, try to see if the url can be accessed, or try another port like 8081

forhonourlx commented 1 month ago

I retried with searxng installation docker run -d -p 8083:8080 -v "${PWD}/searxng:/etc/searxng" -e "BASE_URL=http://0.0.0.0:8080/" -e "INSTANCE_NAME=searxng" searxng/searxng Still got: HTTPConnectionPool(host='localhost', port=8083): Max retries exceeded with url: /?q=SearXNG&format=json&categories=general (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1318374b80>: Failed to establish a new connection: [Errno 111] Connection refused'))

image

HELP!

you can enter the docker container, try to see if the url can be accessed, or try another port like 8081

forhonourlx commented 1 month ago

Tried for days... searxng on localhost:8083 could be access successfully. So what's wrong with my config? image @hjlarry

forhonourlx commented 1 month ago

Any way to diagnosis?

hjlarry commented 1 month ago

enter the docker container to try curl the url, the error is your python code request the url not work

forhonourlx commented 1 month ago

Thanks inadvance.

I notice that 9 containers in dify project, I tried on nginx-1 container, is that right? image

docker gets results:

 docker exec -it a0b265ab7b1d735d3958820cfb4bd63374596411fa0c08bf61830735eef664e3 /bin/bash
root@a0b265ab7b1d:/# curl http://127.0.0.1:8083
curl: (7) Failed to connect to 127.0.0.1 port 8083 after 0 ms: Couldn't connect to server
root@a0b265ab7b1d:/# curl http://localhost:8083
curl: (7) Failed to connect to localhost port 8083 after 0 ms: Couldn't connect to server

and windows gets results:

C:\Users\simon>curl http://localhost:8083
<!DOCTYPE html>
<html class="no-js theme-auto center-aligment-no" lang="en-EN" >
<head>
  <meta charset="UTF-8" />
  <meta name="description" content="SearXNG — a privacy-respecting, open metasearch engine">
  <meta name="keywords" content="SearXNG, search, search engine, metasearch, meta search">
  <meta name="generator" content="searxng/2024.7.29+7d47c961c">
  <meta name="referrer" content="no-referrer">
  <meta name="robots" content="noarchive">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="HandheldFriendly" content="True">
  <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
  <title>searxng</title>
......

enter the docker container to try curl the url, the error is your python code request the url not work

hjlarry commented 1 month ago

the api-1 container is your python codes execute container localhost usually means container self, try http://host.docker.internal:8083 instead, or ask the LLM why can't connect to local computer from docker inside

forhonourlx commented 1 month ago

Many thanks. If using docker searxng, Setting Up Authorization of SearXNG base url http://host.docker.internal:8083 is the answer.