title: nginx and the 405 error
body: <p>I have a pelican blog with a simple contact page.</p>
  
  <p>The contact page uses js to send a POST request to a PHP script which does the SMTP request to send the email. When I try this on the web browser it doesn't work and if I use curl, I get the 405 error:</p>
  
  <pre><code>✗ curl -H "Content-Type: application/json" -X POST -d '{"name":"PM","email":"p@m.com", "message":"foo"}' https://pm.com/theme/send-form.php
  
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;405 Not Allowed&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;405 Not Allowed&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx/1.10.3 (Ubuntu)&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My nginx location directive looks like:</p>
  
  <pre><code>    location / {
               # Serve a .gz version if it exists                                                                
               gzip_static on;
               # Try to serve the clean url version first                                                        
               try_files $uri.html $uri.html $uri =404;
               # allow POST on static pages                                                                      
               error_page 405 =200 $uri;
      }
  
      location ~ \.php$ {
               # If a file isn't found, 404
               try_files $uri =404;
               #Include Nginx's fastcgi configuration
               include /etc/nginx/fastcgi.conf;
               #Look for the FastCGI Process Manager
               fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      }
  </code></pre>
  
  <p>I took inspiration for this location directive from: <a href="https://linuxconfig.org/basic-php-7-and-nginx-configuration-on-ubuntu-16-04-linux" rel="nofollow noreferrer">https://linuxconfig.org/basic-php-7-and-nginx-configuration-on-ubuntu-16-04-linux</a></p>
  
  <p>However, it still doesn't work and the most annoying thing is that there's no evidence of any error in any of the nginx access/error logs or php7.0-fpm error logs.</p>