Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I allow a PUT file request on Nginx server?

Tags:

http

put

nginx

I am using an application which needs to PUT a file on a HTTP server. I am using Nginx as the server but getting a 405 Not Allowed error back. Here is an example of a test with cURL:

curl -X PUT \
-H 'Content-Type: application/x-mpegurl' \
-d /Volumes/Extra/playlist.m3u8 http://xyz.com

And what I get back from Nginx:

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>

What do I need to do to allow the PUT?

Any clues would be awesome!

like image 977
MFB Avatar asked Jun 04 '13 07:06

MFB


People also ask

How enable conf file in nginx?

We can enable a server block's configuration file by creating a symbolic link from the sites-available directory to the sites-enabled directory, which Nginx will read during startup. To do this, enter the following command: sudo ln -s /etc/nginx/sites-available/ example.com /etc/nginx/sites-enabled/

Where do I put html files in nginx?

By default Nginx Web server default location is at /usr/share/nginx/html which is located on the default file system of the Linux.

What is proxy pass in nginx?

The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.


2 Answers

To add HTTP and WebDAV methods like PUT, DELETE, MKCOL, COPY and MOVE you need to compile nginx with HttpDavModule (./configure --with-http_dav_module). Check nginx -V first, maybe you already have the HttpDavModule (I installed nginx from the Debian repository and I already have the module).

Then change your nginx-config like that:

location / {
    root     /var/www;
    dav_methods  PUT;
}

You can get more info on the nginx docs entry for the HttpDavModule.

like image 138
fnkr Avatar answered Sep 17 '22 22:09

fnkr


Another reason for 405 Not Allowed is that you don't have permission to write files on the destination you're PUTing. If you have HttpDavModule and still getting this error, make sure you've given nginx write permissions where you're PUTing the files.

like image 24
Ali Hashemi Avatar answered Sep 17 '22 22:09

Ali Hashemi