logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: 301 errors on POST
Author
zaf



Joined: 15 Feb 2021
Posts: 2
Location: London

PostPosted: Mon 15 Feb '21 16:54    Post subject: 301 errors on POST Reply with quote

Hi Forum,

apache2 v2.4
Ubuntus 20.04
Firefox browser

I am trying to set up Apache2 on my Ubuntu server to have the ability to post files to a directory on the server.

It looks like the GET is OK but the POST fails in relation to the upload of files.
There is no re-directs configured on the server which could cause the 301 as far as I can see.


The access log shows:

127.0.0.1 - brian [15/Feb/2021:11:59:03 +0000] "POST /UPLOADS HTTP/1.1" 301 564 "http://www.zaf/H" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"

127.0.0.1 - brian [15/Feb/2021:11:59:03 +0000] "GET /UPLOADS/ HTTP/1.1" 200 3476 "http://www.zaf/H" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"

Any help appreciated ?

This is the situation so far:

• Configured and installed apache2 on ubuntus 20.04
• Created an apache2 virtual server which appears to work ok
• I can access the home page of the virtual server (ZAF) ok
• I created an upload directory on the server so I can upload files via javascript

The root directory is
/var/www/ZAF

and have an upload directory at:

In /var/www/ZAF/UPLOADS (permission 777)

There are no .htaccess files anywhere within the web server.

I have a virtual configuration file as follows:
The ZAF.conf file is :
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ZAF
ServerAlias www.ZAF
DocumentRoot /var/www/ZAF
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory "/var/www/ZAF/UPLOADS">
AuthType Basic
AuthName "admin area"
AuthUserFile /var/www/ZAF/htpassword
Require valid-user
</Directory>

</VirtualHost>
====================================

The apache2.conf file is


# Global configuration
#ServerRoot "/etc/apache2"

#
#Mutex file:${APACHE_LOCK_DIR} default
DefaultRuntimeDir ${APACHE_RUN_DIR}

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

# access here, or in any related virtual host.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>

<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
AccessFileName .htaccess

<FilesMatch "^\.ht">
Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent


IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

ServerName 127.0.0.1

=========================================

/etc/hosts

127.0.0.1 localhost
127.0.1.1 brian-U55
127.0.1.1 www.ZAF
127.0.1.1 ZAF

==========================================
I do not wish to have any re-directs enabled as this isn’t necessary for what I’m trying to do.


I have the UPLOADS directory authorised which seems ok as when I access it with the firefox browser it asks for a username/password.

I’m getting 301 errors (seen from browser developer tools and the access log) and the file does not upload to the server (UPLOADS directory) when I use several different javascript htmls.
Back to top
mraddi



Joined: 27 Jun 2016
Posts: 152
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Mon 15 Feb '21 21:23    Post subject: Reply with quote

Hello,

please try to post to /UPLOADS/ (with trailing slash) instead of posting to /UPLOADS (without trailing slash). It might be the difference.
As UPLOADS is a directory and not a file apache redirects you to the directory (with a trailing slash) using the 301. But the RFC says that now a GET instead of a POST has to be used ... which will not work for uploading files.

Best regards
Matthias
Back to top
zaf



Joined: 15 Feb 2021
Posts: 2
Location: London

PostPosted: Tue 16 Feb '21 11:34    Post subject: Reply with quote

Many thanks Mraddi,
putting the "/" did the trick.

It's amazing how you can look at something for hours and not see the obvious.

4 eyes is better that 2!
Back to top


Reply to topic   Topic: 301 errors on POST View previous topic :: View next topic
Post new topic   Forum Index -> Apache