apache / apisix

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

bug: Custom Configuration Path not working in standalone mode #11393

Open troke12 opened 3 months ago

troke12 commented 3 months ago

Current Behavior

Currently i tried to custom apisix.yaml path into /mnt/apisix.yaml

my docker compose :

version: '3.9'

services:

  apisix:
    image: apache/apisix:3.9.1-debian
    environment:
      APISIX_STAND_ALONE: "true"
    ports:
      - '9080:9080'
    container_name: apache-apisix
    volumes:
      - ./apisix.yaml:/mnt/apisix.yaml:ro
    restart: always
    command: apisix start --config /mnt/apisix.yaml

my apisix.yaml :

deployment:
  role: data_plane
  role_data_plane:
    config_provider: yaml

routes:
  -
    uri: "/anything/*"
    service_id: 1
    methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
    plugins:
      proxy-rewrite:
        regex_uri: ["^/anything/(.*)", "/$1"]
      cors: {}

services:
  -
    id: 1
    upstream_id: anything_upstream

upstreams:
  -
    id: "anything_upstream"
    nodes:
      "httpbin.org:80": 1
    type: roundrobin

#END

Expected Behavior

No response

Error Logs

apache-apisix  | 2024/07/05 23:45:35 [error] 32#32: *577 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer   
apache-apisix  | 2024/07/05 23:45:35 [error] 37#37: *581 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer   
apache-apisix  | 2024/07/05 23:45:35 [error] 92#92: *585 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer   
apache-apisix  | 2024/07/05 23:45:35 [error] 118#118: *591 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer 
apache-apisix  | 2024/07/05 23:45:35 [error] 85#85: *592 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer   
apache-apisix  | 2024/07/05 23:45:35 [error] 34#34: *597 [lua] config_yaml.lua:73: failed to fetch /usr/local/apisix/conf/apisix.yaml attributes: cannot obtain information from file '/usr/local/apisix/conf/apisix.yaml': No such file or directory, context: ngx.timer 

Steps to Reproduce

  1. Run docker compose up
  2. and got error

Environment

troke12 commented 3 months ago

I tried to another solution where it's worked as well

so, in the command section i added :

command: ["sh", "-c", "cp /mnt/apisix.yaml /usr/local/apisix/conf/ && apisix start --config /usr/local/apisix/conf/apisix.yaml"]

but the auto-reload not working when i added a changes, seems like need to fix that command

zwtesttt commented 2 months ago

In Apache APISIX, different configuration files serve different purposes. By default, there are three configuration files: conf/config.yaml, conf/apisix.yaml, and conf/debug.yaml.

conf/config.yaml:

This file is the global configuration file for Apache APISIX. It contains basic system configurations and key parameters such as port settings, log levels, ETCD configurations, plugin configurations, and more. conf/apisix.yaml:

This file is mainly used to define runtime configurations for routes, services, upstreams, plugins, etc. Users can define various routing rules, services and their corresponding upstream servers, and enable or configure plugins for specific routes in this file. conf/debug.yaml:

This file is used for configurations in debugging and development modes, usually to enable additional logging and debugging information. Relevant links:

Introduction to APISIX configuration files Configuration rules for stand-alone mode When starting in stand-alone mode, the APISIX node service will immediately load the routing rules from the conf/apisix.yaml file into memory (as described in the official documentation). In your command, the --config option is used to specify the conf/config.yaml file, but the node will still load the default conf/apisix.yaml file. This is the cause of the error. If you want to replace the default conf/apisix.yaml with your own apisix.yaml, you can mount it to the corresponding path. The complete docker-compose file is as follows:

version: '3.9'
services:
  apisix:
    image: apache/apisix:3.9.1-debian
    environment:
      APISIX_STAND_ALONE: "true"
    ports:
      - '9080:9080'
    container_name: apache-apisix
    volumes:
      - ./apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro
      # - ./apisix.yaml:/mnt/config.yaml:ro
    restart: always
    # command: apisix start --config /mnt/config.yaml
troke12 commented 2 months ago

In Apache APISIX, different configuration files serve different purposes. By default, there are three configuration files: conf/config.yaml, conf/apisix.yaml, and conf/debug.yaml.

conf/config.yaml:

This file is the global configuration file for Apache APISIX. It contains basic system configurations and key parameters such as port settings, log levels, ETCD configurations, plugin configurations, and more. conf/apisix.yaml:

This file is mainly used to define runtime configurations for routes, services, upstreams, plugins, etc. Users can define various routing rules, services and their corresponding upstream servers, and enable or configure plugins for specific routes in this file. conf/debug.yaml:

This file is used for configurations in debugging and development modes, usually to enable additional logging and debugging information. Relevant links:

Introduction to APISIX configuration files Configuration rules for stand-alone mode When starting in stand-alone mode, the APISIX node service will immediately load the routing rules from the conf/apisix.yaml file into memory (as described in the official documentation). In your command, the --config option is used to specify the conf/config.yaml file, but the node will still load the default conf/apisix.yaml file. This is the cause of the error. If you want to replace the default conf/apisix.yaml with your own apisix.yaml, you can mount it to the corresponding path. The complete docker-compose file is as follows:

version: '3.9'
services:
  apisix:
    image: apache/apisix:3.9.1-debian
    environment:
      APISIX_STAND_ALONE: "true"
    ports:
      - '9080:9080'
    container_name: apache-apisix
    volumes:
      - ./apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro
      # - ./apisix.yaml:/mnt/config.yaml:ro
    restart: always
    # command: apisix start --config /mnt/config.yaml

Yeah i know that, but in the another option is i want to try out the custom path on standalone mode, by mean the configuration that has been set default to the conf/config.yaml should be working on custom path

zwtesttt commented 2 months ago

In Apache APISIX, different configuration files serve different purposes. By default, there are three configuration files: conf/config.yaml, conf/apisix.yaml, and conf/debug.yaml. conf/config.yaml: This file is the global configuration file for Apache APISIX. It contains basic system configurations and key parameters such as port settings, log levels, ETCD configurations, plugin configurations, and more. conf/apisix.yaml: This file is mainly used to define runtime configurations for routes, services, upstreams, plugins, etc. Users can define various routing rules, services and their corresponding upstream servers, and enable or configure plugins for specific routes in this file. conf/debug.yaml: This file is used for configurations in debugging and development modes, usually to enable additional logging and debugging information. Relevant links: Introduction to APISIX configuration files Configuration rules for stand-alone mode When starting in stand-alone mode, the APISIX node service will immediately load the routing rules from the conf/apisix.yaml file into memory (as described in the official documentation). In your command, the --config option is used to specify the conf/config.yaml file, but the node will still load the default conf/apisix.yaml file. This is the cause of the error. If you want to replace the default conf/apisix.yaml with your own apisix.yaml, you can mount it to the corresponding path. The complete docker-compose file is as follows:

version: '3.9'
services:
  apisix:
    image: apache/apisix:3.9.1-debian
    environment:
      APISIX_STAND_ALONE: "true"
    ports:
      - '9080:9080'
    container_name: apache-apisix
    volumes:
      - ./apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro
      # - ./apisix.yaml:/mnt/config.yaml:ro
    restart: always
    # command: apisix start --config /mnt/config.yaml

Yeah i know that, but in the another option is i want to try out the custom path on standalone mode, by mean the configuration that has been set default to the conf/config.yaml should be working on custom path

The --config option allows you to modify the default conf/config.yaml path, but you also need to provide conf/apisix.yaml for it to start correctly. Here is my complete example, which I hope will be helpful to you: docker-compose.yaml:

version: '3.9'

services:
  apisix:
    image: apache/apisix:3.9.1-debian
    environment:
      APISIX_STAND_ALONE: "true"
    ports:
      -  '9080:9080'
    container_name: apache-apisix
    volumes:
      - ./apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro
      - ./config.yaml:/mnt/config.yaml:ro
    restart: always
    command: apisix start --config /mnt/config.yaml

apisix.yaml:

routes:
  -
    uri: "/anything/*"
    service_id: 1
    methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
    plugins:
      proxy-rewrite:
        regex_uri: ["^/anything/(.*)", "/$1"]
      cors: {}

services:
  -
    id: 1
    upstream_id: anything_upstream

upstreams:
  -
    id: "anything_upstream"
    nodes:
      "httpbin.org:80": 1
    type: roundrobin
#END

config.yaml:

deployment:
  role: data_plane
  role_data_plane:
    config_provider: yaml
#END