0

I am trying to set up apache2 server with HTTPS support for uploading files with curl command. It is a 20.04 LTS ubuntu server running apache2 with mod_ssl enabled. When I tried with curl command to upload a file, it gives me HTTP/1.1 405 method not allowed error.

ubuntu@ubuntu:~$ sudo curl -v --insecure -T http-100M.dat https:// example.com/web/

.....

    <HTTP/1.1 405 Method Not Allowed
    <Date: Mon, 20 Jun 2022 19:16:52 GMT
    <Server: Apache/2.4.41 (Ubuntu)
    **<Allow: POST,OPTIONS,HEAD,GET**
    < Content-Length: 299
    < Content-Type: text/html; charset=iso-8859-1
    < 
    <!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.41 (Ubuntu) Server at example.com Port 443</address>

It looks like PUT and POST are not allowed methods by default. So I added a few lines in my -ssl.conf file /etc/apache2/sites-enabled/example.com-ssl.conf and restarted apache2, so it looks like this:

    <VirtualHost *:443>
        ServerAdmin webmaster@localhost
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com
        SSLEngine on
        SSLCertificateKeyFile /etc/ssl/private/example.com.key
        SSLCertificateFile /etc/ssl/certs/example.com.crt
        SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
        Protocols h2 http/1.1
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Alias /web "/var/www/example/html"
      <Directory "/var/www/example/html">
          Options Indexes MultiViews FollowSymLinks Includes ExecCGI.
          AllowOverride All
          Allow from all
          Require all granted
      </Directory>
      <Location /var/www/example/html>
          AllowMethods GET PUT POST
      </Location>

However it didn't help, same error message. Not sure where I did wrong, or whether it is supposed to work in the first place.

Anyone had similar issue?

Thanks!

MikeX
  • 1
  • https://stackoverflow.com/questions/37484888/enable-put-and-delete-methods-on-apache-2-4 maybe? – Daniel Stenberg Jun 21 '22 at 08:02
  • Thanks Daniel. I did actually add a Location block as the following, but it did not help. For Debian/Ubuntu. In your conf: AllowMethods GET PUT In console: sudo a2enmod allowmethods sudo systemctl restart apache2.service – MikeX Jun 29 '22 at 14:24

0 Answers0