'How to configure webhook in nginx?
I am trying to configure the nginx.conf file to receive webhook requests from an external website. The request gets failed with status code 405 (not allowed) when I try to call the webhook using postman. The path of the webhook is /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 {
}
}
Solution 1:[1]
Try removing the trailing slash from the location block as such:
location /hooks {
proxy_pass http://localhost:8000/hooks;
}
The reason why I suspect this may be an issue:
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | snapdeus |