how to enable Http request on Apache server?

how to enable Http request on Apache server?

i want to enable http request on my apache server so i can upload any file to that server with curl -T /path/to/file [server_address/] i tried googling it but the answers were for old version of Apache2, and i'm getting this error if i do that without enabling or something

hamker@hamkerz ~ % curl -T hacc.sh http://3x.142.1xx.81/     
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for this URL.</p>
<hr>
<address>Apache/2.4.38 (Debian) Server at 34.125.172.81 Port 80</address>
</body></html>

Thanks!

答案1

You can use the Limit and LimitExcept directives to remove the 405 Method Not Allowed error you are receiving. An example from this Stack Overflow question for all five of the standard HTTP methods:

<Limit GET HEAD POST PUT DELETE OPTIONS>
    # Apache 2.4 
    Require all granted
</Limit>

Both of the directives above can appear in <Directory> blocks or .htaccess files.

With that said, as far as I am aware, I do not believe simply enabling PUT will allow you to upload files. As (subtly) indicated in the Stack Overflow question above with the directive Dav On, you likely need mod_dav and its related modules mod_dav_fs and mod_dav_lock (which allow WebDAV access) enabled and configured correctly to actually upload files (assuming you aren't using PUT in conjunction with e.g. a PHP script). Beyond the example offered in the official Apache documentation, here is an (outdated but hopefully still useful) Digital Ocean tutorial on setting up WebDAV with Apache on Ubuntu.

相关内容