Any way to restrict HTTP Method?

Hi all,
In nginx, there is a way to restrict HTTP method(s), e.g.

location / {

        limit_except GET {
                deny  all;
        proxy_pass proxy_to_url;

Can Caddy do something similar? If yes, could you show an example?


Hi @caddyrocks, welcome to the Caddy community!

Sorry about your question going unanswered for a few days. This is fairly straightforward, and it involves three features: placeholders, the rewrite directive, and the status directive.

The latter lets you define an arbitrary status response for a given URI, which you can rewrite the request to if the method is not allowed. {
  rewrite {
    if {method} not GET
    to /method_not_allowed
  status 405 /method_not_allowed
} (notably, the if conditions in this doc to select for different methods if needed)

1 Like

Thank you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.