0
votes

Why am I getting a 403 forbidden error only on put request API from CentOS 7 vps server (while get/post are working well)?

The same piece works fine on a shared hosting server and from localhost.

I am using "Nginx + Varnish + Apache"

Whenever I try to execute any PUT request, this is the response:

Forbidden You don't have permission to access /api/path/to/my/api on this server.

3
PUT, PATCH etc. requests aren't supported by default - try using POST/GET (you can pretty much do the same things with these). - JCode
can you add a route that is not working from your routes file ? - Maraboc
Why do you use 3 reverse proxies at the same time? - Namoshek
@Namoshek To get the best performance from VPS. A combo of these three can provide 65% of the total server where Apache alone provides only 35%. - Orbachin Ujbuk
Dear @JCode, Can you tell me why PUT, PATCH are not supported by default? I solved temporarily by calling them by POST request though. - Orbachin Ujbuk

3 Answers

0
votes

You have to explicitly permit PUT requests to your endpoint unlike GET and POST. You should look into your .htaccess settings. This question addresses the same concern and this also.

0
votes

You will have to use POST method along with _method= PUT as a form data:

                let editUrl ="";                     
                 if (this.id) {
                        this.data._method = 'PUT';
                        this.data.id = this.id;
                        editUrl = editUrl + "/" + this.id;
                    }

                  axios.post(editUrl, this.data)
                    .then(resp => {

                    })
                    .catch(() => {

                    });
            }
0
votes

Config your apache virtual host by these conditions:

<Limit GET POST PUT OPTIONS>
    Require all granted
</Limit>
<LimitExcept GET POST PUT OPTIONS>
    Require all denied
</LimitExcept>

Maybe your problem solved.