nginx/php-fpm 405 Error – Fixing Email Contact Form Submission Issues

nginxphp-fpmpostfixsmtpWordpress

I have a small Ubuntu 16.04 VPS that's running nginx/php-fpm to run a WordPress site, and running an SMTP server through Postfix/Saslauthd. My mail server is working just fine at sending and receiving mail, and I have WordPress set up to use SMTP instead of php mail() through the Postman plugin and that works perfectly.

However, when attempting to submit an email contact form through WordPress, I keep getting a 405 Not Allowed error. I tried a couple different contact form plugins (Pirate Forms, Contact Email Form) and still got the same result. I also disabled Postman to force WordPress to use php mail(), but still got a 405.

Nginx debug logs here
Nginx config here.

EDIT: URL I'm trying to post to is https://example.com/contact/

Nginx access log shows this:

xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:07 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:08 -0400] "GET /contact/ HTTP/2.0" 200 6090 "https://example.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:09 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:22 -0400] "POST /contact/ HTTP/2.0" 405 626 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"
xxx.xxx.xxx.xx  - - [09/Oct/2016:20:10:22 -0400] "GET /favicon.ico HTTP/2.0" 200 524 "https://example.com/contact/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36"

Not getting anything in error.log.

Best Answer

You're getting the 405 error because you are passing all requests first to memcached, but it can only handle GET (and HEAD) requests. This upstream therefore returns 405 Method Not Allowed. You need to actually handle this, but at the moment you are ignoring it. I think the easiest way to do it would be to add 405 to the list of errors you handle in error_page.

Related Topic