How to Enable POST to Static Pages Running via NGINX

I am creating a Facebook Canvas Application, and I wanted to use AngularJS to power the dynamic aspects of it as I need to have a two way binding between the front and back end.

When I accessed my initial App which was in PHP and downloaded from GitHub it worked fine and retrieved my name just fine. When I switched over to Angular and then accessed the same endpoint through the Facebook Application view, it threw a 405 page error.

The error comes about because NGINX does not by default allow a POST request to be handled by a static (.html) file.

To enable it; SSH onto your box with a suitably permissioned account (I actually use root on this box).

$ sudo vi /etc/nginx/nginx.conf 

Look for the configuration for the site/domain in question, and it will either have, or need a location block, the line I have marked is in bold.

location / {
  error_page 405 =200 $uri;

Please note the 200 after the = is not a typo, it will not work if you add a space. This line just ensures the response is a 200 (OK) response too.

To check the config before you restart, run this command, please do this and make sure the syntax is OK before you restart or the webserver will not like it at all:

$ sudo /usr/sbin/nginx -t

That will inform you of any syntax errors, before you restart with:

$ sudo /usr/sbin/nginx -s reload

The page should now handle a POST request without throwing a 405 Error.