{"id":26031756,"url":"https://github.com/apache/shenyu-nginx","last_synced_at":"2025-04-10T04:44:56.786Z","repository":{"id":37823715,"uuid":"431077899","full_name":"apache/shenyu-nginx","owner":"apache","description":"Apache ShenYu Nginx.","archived":false,"fork":false,"pushed_at":"2024-04-21T16:13:30.000Z","size":64,"stargazers_count":28,"open_issues_count":1,"forks_count":17,"subscribers_count":30,"default_branch":"main","last_synced_at":"2025-04-03T04:17:06.377Z","etag":null,"topics":["nginx","shenyu"],"latest_commit_sha":null,"homepage":"https://shenyu.apache.org/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-23T11:41:33.000Z","updated_at":"2024-12-23T09:54:08.000Z","dependencies_parsed_at":"2024-04-21T18:13:49.347Z","dependency_job_id":"893577fb-ac73-4fb9-8255-967302ebdbd1","html_url":"https://github.com/apache/shenyu-nginx","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fshenyu-nginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fshenyu-nginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fshenyu-nginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fshenyu-nginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/shenyu-nginx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247715080,"owners_count":20983988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx","shenyu"],"created_at":"2025-03-06T20:58:27.337Z","updated_at":"2025-04-10T04:44:56.763Z","avatar_url":"https://github.com/apache.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"Apache ShenYu Nginx Module\n---\n\nThis module provided SDK to watch available ShenYu instance list as upstream nodes by Service Register Center for OpenResty.\n1. [ETCD](#greeting-etcd) (Supported)\n2. [Nacos](#greeting-nacos) (Supported)\n3. [Zookeeper](#greeting-zookeeper) (Supported)\n4. [Consul](#greeting-consul) (Supported)\n\nIn the cluster mode, Apache ShenYu supports the deployment of multiple ShenYu instances, which may have new instances joining or leaving at any time.\nHence, Apache ShenYu introduces Service Discovery modules to help client to detect the available instances.\nCurrently, Apache ShenYu Bootstrap already supports Apache Zookeeper, Nacos, Etcd, and consul. Client or LoadBalancer can get the available ShenYu instances by those Service register center.\n\nHere provides a completed [examples](https://github.com/apache/shenyu-nginx/tree/main/example).\n\n=======\n\nHere is a completed [example](https://github.com/apache/shenyu-nginx/blob/main/example/etcd/nginx.conf) working with ETCD.\n\nHere is a completed [example](https://github.com/apache/shenyu-nginx/blob/main/example/nacos/nginx.conf) working with Nacos.\n\nHere is a completed [example](https://github.com/apache/shenyu-nginx/blob/main/example/consul/nginx.conf) working with Consul.\n\nHere is a completed [example](https://github.com/apache/shenyu-nginx/blob/main/example/zookeeper/nginx.conf) working with Zookeeper.\n\n## Getting Started\n\n- Prerequisite:\n1. Luarocks\n2. OpenResty\n\n### Build from source\n\nThe first, clone the source from GitHub.\n\n```shell\ngit clone https://github.com/apache/shenyu-nginx\n```\n\nThen, build from source and install.\n\n```shell\ncd shenyu-nginx\nluarocks make rockspec/shenyu-nginx-1.0.0-2.rockspec\n```\n\n### Greeting ETCD\n\nModify the Nginx configure, create and initialize the ShenYu Register to connect to the target register center.\nThe module will fetch the all of ShenYu instances which are registered to Etcd in the same cluster.\nIt works like Etcd client to watch(based on long polling) ShenYu instance lists.\n\nHere is an example for Etcd.\n\n```\ninit_worker_by_lua_block {\n    local register = require(\"shenyu.register.etcd\")\n    register.init({\n        balancer_type = \"chash\",\n        etcd_base_url = \"http://127.0.0.1:2379\",\n    })\n}\n```\n\n1. `balancer_type` specify the balancer. It has supported `chash` and `round robin`.\n2. `etcd_base_url` specify the Etcd server.(Currently, authentication is not supported.)\n\nAdd an `upstream block` for ShenYu and enable to update upstream servers dynamically. This case will synchronize the ShenYu instance list with register center.\nAnd then pick one up for handling the request.\n\n```\nupstream shenyu {\n    server 0.0.0.1; -- bad \n    \n    balancer_by_lua_block {\n        require(\"shenyu.register.etcd\").pick_and_set_peer()\n    }\n}\n```\n\n\n### Greeting Nacos\n\nModify the Nginx configure, create and initialize the ShenYu Register to connect to target register center.  Here is an example for Nacos.\n\n```\ninit_worker_by_lua_block {\n    local register = require(\"shenyu.register.nacos\")\n    register.init({\n        shenyu_storage = ngx.shared.shenyu_storage,\n        balancer_type = \"chash\",\n        nacos_base_url = \"http://127.0.0.1:8848\",\n        username = \"nacos\",\n        password = \"naocs\",\n    })\n}\n```\n\n1. `balancer_type` specify the balancer. It has supported `chash` and `round robin`.\n2. `nacos_base_url` specify the Nacos server address.\n3. `username` specify the username to log in Nacos. (it is only required when Nacos auth enable)\n4. `password` specify the password to log in Nacos.\n\nModify the `upstream` to enable to update upstream servers dynamically. This case will synchronize the ShenYu instance list with register center.\nAnd then pick one up for handling the request.\n\n```\nupstream shenyu {\n    server 0.0.0.1; -- bad \n    \n    balancer_by_lua_block {\n        require(\"shenyu.register.nacos\").pick_and_set_peer()\n    }\n}\n```\n\n## Greeting Zookeeper\n\nModify the Nginx configure, create and initialize the ShenYu register to connect to target register center.\nListen for changes to the node via the zookeeper watch event. Here is an example of the zookeeper configuration.\n\n```shell\ninit_worker_by_lua_block {\n        local register = require(\"shenyu.register.zookeeper\")\n        register.init({\n           servers = {\"127.0.0.1:2181\",\"127.0.0.1:2182\"},\n           shenyu_storage = ngx.shared.shenyu_storage,\n           balancer_type = \"roundrobin\"\n        });\n    }\n```\n\n1. `servers` zookeeper cluster address.\n2. ``balancer_type`` specify the balancer. It has supported `chash` and `round robin`.\n\nModify the upstream to enable to update upstream servers dynamically. This case will synchronize the ShenYu instance list with register center. And then pick one up for handling the request.\n\n```shell\n upstream shenyu {\n        server 0.0.0.1;\n        balancer_by_lua_block {\n            require(\"shenyu.register.zookeeper\").pick_and_set_peer()\n        }\n    }\n```\n\n### Greeting Consul\n\nModify the Nginx configure, create and initialize the ShenYu register to connect to target register center.\nListen for changes to the node via the consul watch event. Here is an example of the consul configuration.\n\n```shell\ninit_worker_by_lua_block {\n    local register = require \"shenyu.register.consul\";\n    register.init({\n        uri = \"http://127.0.0.1:8500\",\n        path = \"/v1/catalog/service/demo\",\n        shenyu_storage = ngx.shared.shenyu_storage,\n        balancer_type = \"chash\",\n    })\n}\n```\n\n1. ``balancer_type`` specify the balancer. It has supported `chash` and `round robin`.\n2. `uri` consul server address.\n3. `path` path of service.\n\nModify the upstream to enable to update upstream servers dynamically. This case will synchronize the ShenYu instance list with register center. And then pick one up for handling the request.\n\n```shell\n\n upstream shenyu {\n        server 0.0.0.1;\n        balancer_by_lua_block {\n            require(\"shenyu.register.consul\").pick_and_set_peer()\n        }\n    }\n```\n\n## Finally\n\nFinally, restart OpenResty.\n\n```shell\nopenresty -s reload\n```\n\n\n## Contributor and Support\n\n* [How to Contributor](https://shenyu.apache.org/community/contributor-guide)\n* [Mailing Lists](mailto:dev@shenyu.apache.org)\n\n## License\n\n[Apache License 2.0](https://apache.org/licenses/LICENSE-2.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fshenyu-nginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fshenyu-nginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fshenyu-nginx/lists"}