Contact form doesn't work on Ubuntu VPN- DigitalOcean - error 405 Not Allowed nginx/1.4.6 (Ubuntu)

May 1, 2015 2.6k views
Nginx Deployment PHP Ubuntu

I am hosting my website on VPN- DigitalOcean.

I installed NGinx, sendmail packages on ubuntu but I kept trying to

I kept having this problem whenever I try to send an email through contact form. The contact form uses php script
**
405 Not Allowed
nginx/1.4.6 (Ubuntu)
**

I tried different solutions I found on the internet like this but couldnt overcome the problem.

Any advise on how to solve this. It seems that nginx is blocking php scripts.

1 comment
  • @yucivictech

    If you'll visit http://hastebin.com/ and show us what you've setup for:

    1). NGINX Configuration File (/etc/nginx/nginx.conf)
    2). NGINX Domain Configuration File (/etc/nginx/sites-enabled/yourdomain.conf)
    3). PHP-FPM Configuration File (/etc/php5/fpm/php-fpm.conf)
    4). PHP-FPM Pool Configuration File (/etc/php5/fpm/pool.d/[poolname].conf)

    That'll at least get us started :-). Using those files, we can see if there's something wrong/missing and help you get things working.

2 Answers

Hi! Can you post the HTML source code of the contact form? Specifically the <form ...> line. What method is it using?

<form method="POST" action="contact.php">
.
.
</form>

I'm made aware that POST method is not allowed in static html with nginx but I've been searching for the right config all over the internet and none of the suggested solution work for me.

@kamaln7

Can you help point me in the right direction? Appreciate it so much. Thanks ;)

  • Hi @yansusanto — are you getting the exact same error with method="POST"? Nginx definitely supports POST, but not PUT (on static files/requests that are not passed to php).

    • Yeah, for it to work without getting the 405 error, I have to add this

          location / {
              try_files $uri $uri/ =404;
              error_page 405 =200 $uri;
          }
      

      But that's just the first of the problems (lol) the same contact form script that works on shared hosting doesn't seem to work here.

Have another answer? Share your knowledge.