PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] How to configure webhook in nginx?

 September 01, 2022     amazon-ec2, nginx, nginx-location, nginx-reverse-proxy, webhooks     No comments   

Issue

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

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.



Answered By - snapdeus
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing