Upload module forbidden

hi all ,

  i am uploading files via nginx upload module . in my configuration



   location     /upload {



}
this will be matched with post request .but when i upload file
.file is uploaded successfully response to the client is 403 .

   when i see log file it is showing directory indexof

/usr/local/nginx/html/upload/ is forbidden ?

if someone knows plz tell me .

thanks in advance

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,188434,188434#msg-188434

On Tue, Apr 05, 2011 at 02:17:30AM -0400, vetri wrote:

Hi there,

there seem to be lots of mails reporting lots of problems with your
configuration. Presumably something is not being done right, or you are
finding something unclear about the documentation.

To step back a bit:

in order for you to upload a file via http, you must write a html form
which includes at least one “” field, which the client
gets; and you must write an upload-form-handler which nginx has access
to,
either via proxy_pass to another http server, or via fastcgi_pass to a
fastcgi server, or via one of the other “dynamic” mechanisms (scgi_pass,
uwsgi_pass, etc).

You seem to have written the form, and sent it to the client. That’s
good.

I don’t see any obvious evidence that you have written the form-handler.

Have you? And if so, how does nginx send the request to your handler? As
in, what url does nginx access, and by what means (proxy_pass,
fastcgi_pass, other)?

/usr/local/nginx/html/upload/ is forbidden ?

if someone knows plz tell me .

I guess that you are trying to POST to a url like /directory, and are
being redirected to /directory/, and then you try to GET /directory/
which has not been configured to e allowed.

But that’s pretty much just a symptom of the broken setup, and so not
too important.

The important bit is: where is your form handler?

Good luck,

f

Francis D. [email protected]

mr francis ,

i am uploading files via form to nginx .here below i have written my
config

worker_processes 20;

error_log logs/error.log notice;

working_directory /usr/local/nginx;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
listen 80;
client_max_body_size 100m;

Upload form should be submitted to this location

location /upload {

Pass altered request body to this location

upload_pass @test;

Store files to this directory

The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should

exist
upload_store /tmp 1;

Allow uploaded files to be read only by user

upload_store_access user:r;

Set specified fields in request body

upload_set_form_field “${upload_field_name}_name” $upload_file_name;
upload_set_form_field “${upload_field_name}_content_type”
$upload_content_type;
upload_set_form_field “${upload_field_name}_path” $upload_tmp_path;

Inform backend about hash and size of a file

upload_aggregate_form_field “${upload_field_name}_md5”
$upload_file_md5;
upload_aggregate_form_field “${upload_field_name}_size”
$upload_file_size;

upload_pass_form_field “^submit$|^description$”;
}

Pass altered request body to a backend

location @test {
proxy_pass http://localhost:8080;
}
}
server{
listen 8080;
}
}
can u tell me why it is returning forbidden after file is uploaded?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,188434,188448#msg-188448

On Tue, Apr 05, 2011 at 05:08:08AM -0400, vetri wrote:

Hi there,

i am uploading files via form to nginx .here below i have written my
config

You must have your own code to handle the POST data. It will be a cgi
script, or a fastcgi script, or a servlet, or something like that.

Pass altered request body to this location

upload_pass @test;

This says “your own code is available at @test”.

Pass altered request body to a backend

location @test {
proxy_pass http://localhost:8080;
}

This says “your own code is really at http://localhost:8080/upload”.

server{
listen 8080;
}
}

but you do not have your own code there.

can u tell me why it is returning forbidden after file is uploaded?

Because http://localhost:8080/upload corresponds to a directory.

You must tell nginx where your own form-handling code is.

Where is it?

f

Francis D. [email protected]

mr kunz,

    if i dont specify the backend server on 8080 , it will show bad

gateway error . uploading is fine .

mr francis,

         why should i keep the code in the upload folder.server

willl handle uploaded files.

thanks for the reply

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,188434,188459#msg-188459

On Tue, Apr 05, 2011 at 06:47:46AM -0400, vetri wrote:

Hi there,

If my question is unclear, please say so, and we can try to make it
clearer.

If my question is clear, please answer it.

Otherwise you are unlikely to get useful help.

You must have your own code to handle the POST data. You must
configure nginx to know how to access that code.

Where is that code?

f

Francis D. [email protected]

Hello vetri,

what should happen on port 8080? Or, what happens if you post directly
to http://localhost:8080
It seems, 8080 can not handle your upload…

Am 05.04.2011 11:08, schrieb vetri:

server{
listen 8080;
}

Cheers,

Alexander

mr francis,

 i have written my nginx configuration above . that is the

configuration i am using to upload file .

mr alexander,

       my goal is to save the file in the real name (or) pass the

temporary name to backend server as query .

      can i do that?

thanks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,188434,188484#msg-188484

I would rethink if this module is the right pice of software for your
needs, currently you
get uploaded files with a temp filename, nothing more… If this is
your goal take a look at

Am 05.04.2011 11:08, schrieb vetri:

server{
listen 8080;
}

Am 05.04.2011 12:47, schrieb vetri:

mr kunz,

     if i dont specify the backend server on 8080 , it will show bad

gateway error . uploading is fine .

It’s not enought to “specify” a backend, the backend must do something
:slight_smile: Like answer with
some code 200.

Or go the right way and…

Am 05.04.2011 12:55, schrieb Francis D.:

Youmust have your own code to handle the POST data. Youmust
configure nginx to know how to access that code.

Where is that code?

Cheers,

Alexander

Hello vetri,

shure, but not without a backend. Renaming the temp file is a job for
your Backend. If you can/will not
use somthing linke php/jsp/asp you can try embedding the LUA engine into
nginx, there a lot of mails in
this list from agentzh and me (questions from me, very helpful answers
from agentzh) but, be aware
renaming with lua is blocking.

Btw. reading c code from this module will be helpful, i am no c
developer but its not so hard to understand
whats happen…

Cheers,

Alexander

Am 05.04.2011 15:43, schrieb vetri:

hi francis,

      what did u do to upload files ? can u give me your code ?and

how to use stock nginx can we really upload files using stock nginx?

thanks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,188434,188661#msg-188661

On Tue, Apr 05, 2011 at 09:43:58AM -0400, vetri wrote:

Hi there,

 i have written my nginx configuration above . that is the

configuration i am using to upload file .

Maybe that is where it became unclear: I wrote “code”; you read
“configuration”.

Please read the previous mail again, but where I say “your code”, I mean
something like “the backend url”.

       my goal is to save the file in the real name (or) pass the

temporary name to backend server as query .

What url on the backend server should nginx send the POST form data to?

      can i do that?

Yes. “upload_pass” must be set to get the request to the backend server.

Aside: to upload a file, you do not need the upload module. You can
just use stock nginx. The upload module should make the backend code
that handles the form data a bit easier. If it doesn’t do that, you can
omit the upload module and just handle the whole thing in your own code.

Good luck with it,

f

Francis D. [email protected]

On Wed, Apr 06, 2011 at 12:09:22AM -0400, vetri wrote:

Hi there,

      what did u do to upload files ? can u give me your code ?and

It is absolutely normal cgi-type programming. There’s probably a forum
for that somewhere else.

For example, the following php script called my-form-handler:

===

<?php
header(“Content-Type: text/plain”);
print("GET: "); print_r($_GET);
print("POST: "); print_r($_POST);
print("FILES: "); print_r($_FILES);
?>

with the following nginx config snippet:

===
include fastcgi.conf;
location = /my-form-handler {
fastcgi_pass unix:php.sock;
}

will show you what you get when you GET or POST to /my-form-handler.

You can then adjust that script to do whatever you want it to do with
your own input.

how to use stock nginx can we really upload files using stock nginx?

Yes: you use stock nginx plus your own form handler; or nginx plus
upload
module plus your own form handler.

But you still have to have your own form handler.

If you use upload module, then you can use

upload_pass /my-form-handler;

among the rest of the upload module config.

Test with something like

curl -i -F [email protected] -F submit=on http://localhost/my-form-handler

or

curl -i -F [email protected] -F submit=on http://localhost/upload

As it happens, the php engine does some of what the upload module does,
as regards processing the input stream and splitting it into files. So
you may see a bigger benefit to using upload module if you use a
different
backend technology.

But it looks like the nginx side of the problem is resolved, unless you
have a specific follow-up question.

Good luck with it,

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs