apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.43k stars 2.51k forks source link

request help: failed to connect to the unix socket unix:/usr/local/apisix/conf/apisix-1.sock: no such file or directory #11544

Closed boh001 closed 1 month ago

boh001 commented 1 month ago

Description

Issue description

Sending a request to http://localhost:9080 will result in an error. I'm running apisix in docker.

Error

2024/09/01 04:11:33 [error] 33#33: *396 [lua] init.lua:889: phase_func(): failed to connect to the unix socket unix:/usr/local/apisix/conf/apisix-1.sock: no such file or directory

Dockerfile

FROM golang:1.22.5 AS plugin-builder

WORKDIR /builder

COPY go-runner .

RUN CGO_ENABLED=0 go build .

FROM apache/apisix:3.9.1-debian

ENV APISIX_STAND_ALONE=true

EXPOSE 9080 9180 9091 9443 9092

COPY apisix.yaml /usr/local/apisix/conf/apisix.yaml

COPY --from=plugin-builder /builder/go-runner /usr/local/apisix-go-plugin-runner/go-runner

apisix.yaml

routes:
  - uri: /
    plugin_config_id: 1
    upstream:
      nodes:
        "upstream-nlb-9780037035286027.elb.ap-northeast-2.amazonaws.com": 1
      type: roundrobin

plugin_configs:  
  - id: 1
    plugins:
      ext-plugin-pre-req:
        name: ext-plugin-pre-req
        config:
          name: "say"
          value:
            body: "Hello, APISIX!"

ext-plugin:
  cmd: ["/usr/local/apisix-go-plugin-runner/go-runner", "run"]
#END

Furthermore, when I checked /usr/local/apisix/config in Docker, there is no sock file and no environment variable named APISIX_LISTEN_ADDRESS.

apisix@fe350b633c44:/usr/local/apisix/conf$ ls
apisix.uid  apisix.yaml  cert  config-default.yaml  config.yaml  debug.yaml  mime.types  nginx.conf
apisix@fe350b633c44:/usr/local/apisix/conf$ printenv
APISIX_STAND_ALONE=true
HOSTNAME=fe350b633c44
PWD=/usr/local/apisix/conf
HOME=/home/apisix
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
_=/usr/bin/printenv
OLDPWD=/usr/local/apisix

Environment

zhoujiexiong commented 1 month ago

@boh001

ext-plugin should be placed in config.yaml, not apisix.yaml

config.yaml

deployment:
  role: data_plane
  role_data_plane:
    config_provider: yaml
  admin:
    admin_key:
      - name: admin
        key: edd1c9f034335f136f87ad84b625c8f1  # using fixed API token has security risk, please update it when you deploy to production environment
        role: admin
ext-plugin:
  cmd: ["/usr/local/apisix-go-plugin-runner/go-runner", "run"]

Attach the Dockerfile I used to test.

FROM golang:1.22.5 AS plugin-builder
WORKDIR /builder
COPY apisix-go-plugin-runner/. .
RUN go env -w GOPROXY='https://goproxy.cn,direct'
RUN go env -w GOFLAGS=-buildvcs=false
RUN CGO_ENABLED=0 make build

FROM apache/apisix:3.9.1-debian
ENV APISIX_STAND_ALONE=true
EXPOSE 9080 9180 9091 9443 9092
COPY apisix.yaml /usr/local/apisix/conf/apisix.yaml
COPY config.yaml /usr/local/apisix/conf/config.yaml
COPY --from=plugin-builder /builder/go-runner /usr/local/apisix-go-plugin-runner/go-runner

And related CMDs. :D

cd $YOUR_WORKSPACE - where your Dockerfile/apisix.yaml/config.yaml files are placed
git clone https://github.com/apache/apisix-go-plugin-runner.git
docker build . -t issue_11544
docker run --rm -p 39080:9080 issue_11544
curl -I localhost:39080
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Content-Length: 18
Connection: keep-alive
Date: Tue, 03 Sep 2024 08:19:51 GMT
Server: APISIX/3.9.1
boh001 commented 1 month ago

resolved. thank you