# Upload module forbidden

**URL:** <https://www.ruby-forum.com/t/upload-module-forbidden/205360>\
**Category:** NGINX\
**Created:** [April 5, 2011, 8:17am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360 "2011-04-05T08:17:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 5, 2011, 8:17am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/1 "2011-04-05T08:17:45Z")

</div>

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:

> **[upload module forbidden](https://forum.nginx.org/read.php?2,188434,188434#msg-188434)**
>
> 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

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 11:00am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/2 "2011-04-05T11:00:10Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 11:08am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/3 "2011-04-05T11:08:50Z")

</div>

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](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](http://forum.nginx.org/read.php?2,188434,188448#msg-188448)

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 11:41am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/4 "2011-04-05T11:41:00Z")

</div>

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](http://localhost:8080);  
> }

This says “your own code is really at [http://localhost:8080/upload](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](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 12:48pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/5 "2011-04-05T12:48:21Z")

</div>

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:

> **[Re: upload module forbidden](https://forum.nginx.org/read.php?2,188434,188459#msg-188459)**
>
> 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

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 12:55pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/6 "2011-04-05T12:55:45Z")

</div>

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. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 11:46am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/7 "2011-04-05T11:46:34Z")

</div>

Hello vetri,

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

Am 05.04.2011 11:08, schrieb vetri:

> server{  
> listen 8080;  
> }

Cheers,

Alexander

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 3:44pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/8 "2011-04-05T15:44:36Z")

</div>

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:

> **[Re: upload module forbidden](https://forum.nginx.org/read.php?2,188434,188484#msg-188484)**
>
> 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

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 1:52pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/9 "2011-04-05T13:52:08Z")

</div>

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  
🙂 Like answer with  
some code 200.

Or go the right way and…

Am 05.04.2011 12:55, schrieb Francis D.:

> 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?

Cheers,

Alexander

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 4:01pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/10 "2011-04-05T16:01:18Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 6, 2011, 6:09am UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/11 "2011-04-06T06:09:47Z")

</div>

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:

> **[Re: upload module forbidden](https://forum.nginx.org/read.php?2,188434,188661#msg-188661)**
>
> 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

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 5, 2011, 7:32pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/12 "2011-04-05T19:32:37Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [April 6, 2011, 2:17pm UTC](https://www.ruby-forum.com/t/upload-module-forbidden/205360/13 "2011-04-06T14:17:24Z")

</div>

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 f=@testfile -F submit=on [http://localhost/my-form-handler](http://localhost/my-form-handler)

or

curl -i -F f=@testfile -F submit=on [http://localhost/upload](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
