{"id":27081613,"url":"https://github.com/api7/wasm-nginx-module","last_synced_at":"2025-04-06T02:20:01.232Z","repository":{"id":37830605,"uuid":"407052884","full_name":"api7/wasm-nginx-module","owner":"api7","description":"Run Wasm in OpenResty/Nginx","archived":false,"fork":false,"pushed_at":"2024-02-21T02:55:02.000Z","size":282,"stargazers_count":175,"open_issues_count":11,"forks_count":20,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-02-21T03:49:47.037Z","etag":null,"topics":["nginx","openresty","wasm"],"latest_commit_sha":null,"homepage":"","language":"C","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/api7.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-09-16T06:45:16.000Z","updated_at":"2024-02-07T10:08:30.000Z","dependencies_parsed_at":"2024-02-21T03:45:10.936Z","dependency_job_id":"56a9f1b6-fc2f-4831-b6d9-6fa7779cc672","html_url":"https://github.com/api7/wasm-nginx-module","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/api7%2Fwasm-nginx-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/api7%2Fwasm-nginx-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/api7%2Fwasm-nginx-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/api7%2Fwasm-nginx-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/api7","download_url":"https://codeload.github.com/api7/wasm-nginx-module/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423939,"owners_count":20936691,"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","openresty","wasm"],"created_at":"2025-04-06T02:20:00.514Z","updated_at":"2025-04-06T02:20:01.221Z","avatar_url":"https://github.com/api7.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n  ~ Copyright 2022 Shenzhen ZhiLiu Technology Co., Ltd.\n  ~\n  ~ Licensed under the Apache License, Version 2.0 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ http://www.apache.org/licenses/LICENSE-2.0\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" BASIS,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  ~\n--\u003e\n## Status\n\nThis library is under construction. See https://github.com/api7/wasm-nginx-module/issues/25 to know the progress.\n\n## Description\n\nA Nginx module which tries to implement [proxy wasm ABI](https://github.com/proxy-wasm/spec) in Nginx.\nThe [Wasm integration of Apache APISIX](https://github.com/apache/apisix/blob/master/docs/en/latest/wasm.md) is powered by this module.\n\n## Install dependencies\n\n* Download the wasmtime C API package and rename it to `wasmtime-c-api/`, with the `./install-wasmtime.sh`.\nRemember to add the `wasmtime-c-api/lib` to the library search path when you build Nginx, for instance,\n\n```\nexport wasmtime_prefix=/path/to/wasm-nginx-module/wasmtime-c-api\n./configure ... \\\n    --with-ld-opt=\"-Wl,-rpath,${wasmtime_prefix}/lib\" \\\n```\n\n* Download WasmEdge with the `./install-wasmedge.sh`.\nRemember to add the `wasmedge/lib` to the library search path when you build Nginx, for instance,\n\n```\nexport wasmedge_prefix=/path/to/wasm-nginx-module/wasmedge\n./configure ... \\\n    --with-ld-opt=\"-Wl,-rpath,${wasmedge_prefix}/lib\" \\\n```\n\n## Directives\n\n### wasm_vm\n\n**syntax:** *wasm_vm wasmtime|wasmedge*\n\n**default:** -\n\n**context:** *http*\n\nSelect the Wasm VM. Currently, only wasmtime and WasmEdge are supported.\nIf the directive is not set, the Wasm VM won't be enabled.\n\n## Methods\n\n**Remember to set the `wasm_vm` directive!**\n\n### load\n\n`syntax: plugin, err = proxy_wasm.load(name, path)`\n\nLoad a `.wasm` file from the filesystem and return a Wasm plugin.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/plugin_lifecycle/main.go.wasm\")\n```\n\n### on_configure\n\n`syntax: plugin_ctx, err = proxy_wasm.on_configure(plugin, conf)`\n\nCreate a plugin ctx with the given plugin and conf.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/plugin_lifecycle/main.go.wasm\")\nif not plugin then\n    ngx.log(ngx.ERR, \"failed to load wasm \", err)\n    return\nend\nlocal ctx, err = wasm.on_configure(plugin, '{\"body\":512}')\nif not ctx then\n    ngx.log(ngx.ERR, \"failed to create plugin ctx \", err)\n    return\nend\n```\n\n### on_http_request_headers\n\n`syntax: ok, err = proxy_wasm.on_http_request_headers(plugin_ctx)`\n\nRun the HTTP request headers filter in the plugin of the given plugin ctx.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/plugin_lifecycle/main.go.wasm\")\nif not plugin then\n    ngx.log(ngx.ERR, \"failed to load wasm \", err)\n    return\nend\nlocal ctx, err = wasm.on_configure(plugin, '{\"body\":512}')\nif not ctx then\n    ngx.log(ngx.ERR, \"failed to create plugin ctx \", err)\n    return\nend\nassert(wasm.on_http_request_headers(ctx))\n```\n\n### on_http_request_body\n\n`syntax: ok, err = proxy_wasm.on_http_request_body(plugin_ctx, body, end_of_body)`\n\nRun the HTTP request body filter in the plugin of the given plugin ctx.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/plugin_lifecycle/main.go.wasm\")\nif not plugin then\n    ngx.log(ngx.ERR, \"failed to load wasm \", err)\n    return\nend\nlocal ctx, err = wasm.on_configure(plugin, '{\"body\":512}')\nif not ctx then\n    ngx.log(ngx.ERR, \"failed to create plugin ctx \", err)\n    return\nend\n-- get_body is a utility method to get the whole request body\nlocal body = request.get_body()\n-- if the body is not the whole request body, for example, it comes from\n-- lua-resty-upload, remember to set end_of_body to false\nassert(wasm.on_http_request_body(ctx, body, true))\n```\n\n### on_http_response_headers\n\n`syntax: ok, err = proxy_wasm.on_http_response_headers(plugin_ctx)`\n\nRun the HTTP response headers filter in the plugin of the given plugin ctx.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/http_lifecycle/main.go.wasm\")\nif not plugin then\n    ngx.log(ngx.ERR, \"failed to load wasm \", err)\n    return\nend\nlocal ctx, err = wasm.on_configure(plugin, '{\"body\":512}')\nif not ctx then\n    ngx.log(ngx.ERR, \"failed to create plugin ctx \", err)\n    return\nend\nassert(wasm.on_http_response_headers(ctx))\n```\n\n### on_http_response_body\n\n`syntax: ok, err = proxy_wasm.on_http_response_body(plugin_ctx)`\n\nRun the HTTP response body filter in the plugin of the given plugin ctx.\nThis method need to be called in `body_filter_by_lua` phase and may be run\nmultiple times.\n\n```lua\nlocal plugin, err = proxy_wasm.load(\"plugin\",\"t/testdata/http_lifecycle/main.go.wasm\")\nif not plugin then\n    ngx.log(ngx.ERR, \"failed to load wasm \", err)\n    return\nend\nlocal ctx, err = wasm.on_configure(plugin, '{\"body\":512}')\nif not ctx then\n    ngx.log(ngx.ERR, \"failed to create plugin ctx \", err)\n    return\nend\nassert(wasm.on_http_response_body(ctx))\n```\n\n## proxy-wasm ABI\n\nImplemented proxy-wasm ABI can be found in [proxy_wasm_abi](./proxy_wasm_abi.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapi7%2Fwasm-nginx-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapi7%2Fwasm-nginx-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapi7%2Fwasm-nginx-module/lists"}