如何在 nginx 中配置 webhook?

How to configure webhook in nginx?

我正在尝试配置 nginx.conf 文件以接收来自外部网站的 webhook 请求。当我尝试使用邮递员调用 webhook 时,请求失败,状态代码为 405(不允许)。 webhook 的路径是 /hooks

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
#    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
        server_name _;
         root /etc/nginx/code/build;
         location / {
              try_files $uri /index.html;
        }
        error_log  /var/log/nginx/jackfruit.error_log  debug;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        #include /etc/nginx/sites-enabled/*;
        #location / {
        #}
        location /api {
             proxy_pass http://localhost:8000;
       }
        location /hooks/ {
             proxy_pass http://localhost:8000/hooks;
       }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

    }

尝试从 location 块中删除尾部斜线:

location /hooks {
         proxy_pass http://localhost:8000/hooks;
   }

我怀疑这可能是个问题的原因:

If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, or memcached_pass, then in response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended.