Skip to content

Commit e7b5a19

Browse files
fix(nginx-openresty): reject unknown HTTP methods with 405
Add access_by_lua_block at server level to reject methods other than GET, HEAD, and POST with 405 Method Not Allowed. Requested by @joanhey in PR #99.
1 parent 5f5829d commit e7b5a19

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

frameworks/nginx-openresty/nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ http {
3535
server {
3636
listen 8080 reuseport;
3737

38+
# Reject unknown HTTP methods — only allow GET, HEAD, POST
39+
access_by_lua_block {
40+
local m = ngx.req.get_method()
41+
if m ~= "GET" and m ~= "HEAD" and m ~= "POST" then
42+
ngx.status = 405
43+
ngx.header["Content-Type"] = "text/plain"
44+
ngx.say("Method Not Allowed")
45+
return ngx.exit(405)
46+
end
47+
}
48+
3849
location /pipeline { content_by_lua_block { require("handler").pipeline() } }
3950
location /baseline11 { content_by_lua_block { require("handler").baseline11() } }
4051
location /baseline2 { content_by_lua_block { require("handler").baseline2() } }

0 commit comments

Comments
 (0)