# Nginx upload module (v 2.2.0) :: 502 Bad Gateway

**URL:** <https://www.ruby-forum.com/t/nginx-upload-module-v-2-2-0-502-bad-gateway/211474>\
**Category:** NGINX\
**Created:** [September 5, 2011, 9:00am UTC](https://www.ruby-forum.com/t/nginx-upload-module-v-2-2-0-502-bad-gateway/211474 "2011-09-05T09:00:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 5, 2011, 9:00am UTC](https://www.ruby-forum.com/t/nginx-upload-module-v-2-2-0-502-bad-gateway/211474/1 "2011-09-05T09:00:48Z")

</div>

HI,

I have compiled newest version of nginx (nginx/1.1.1) with nginx upload  
module (v 2.2.0), also the example config (nginx.conf) was copied from  
[GitHub - vkholodkov/nginx-upload-module: A module for nginx web server for handling file uploads using multipart/form-data encoding (RFC 1867).](https://github.com/vkholodkov/nginx-upload-module) into nginx direcoty.  
The html form is also copied from this location. So the installation and  
configuration is oryginal now without any changes.

I’m getting some errors while uploading the file;

The html form: ‘502 Bad Gateway’;

The nginx error.log (/usr/local/nginx/logs/error.log):

* * *

## 2011/09/05 08:35:15 [error] 21161#0: \*6 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.165, server: , request: “POST /upload HTTP/1.1”, upstream: “[http://127.0.0.1:8080/upload](http://127.0.0.1:8080/upload)”, host: “192.168.0.127”, referrer: “[http://192.168.0.127/http/upload.html](http://192.168.0.127/http/upload.html)”

Maybe it’s a problem of my wrong understanding how does it works, I do  
not understand why in this example config the proxy\_pass is going  
through local 8080 port but the server in this configuration is not  
listening on such port.

Please help.

–  
best regards  
Piotr P.

---

<div class="post-metadata">

**Author:** ![ppalka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/aeb1de/32.png) [@ppalka](https://www.ruby-forum.com/u/ppalka)\
**Post date:** [September 5, 2011, 11:12am UTC](https://www.ruby-forum.com/t/nginx-upload-module-v-2-2-0-502-bad-gateway/211474/2 "2011-09-05T11:12:31Z")

</div>

On Mon, 05 Sep 2011 08:59:58 +0200, Piotr P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## I’m getting some errors while uploading the file; The html form: ‘502 Bad Gateway’; The nginx error.log (/usr/local/nginx/logs/error.log):
> 
> ## 2011/09/05 08:35:15 [error] 21161#0: \*6 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.165, server: , request: “POST /upload HTTP/1.1”, upstream: “[http://127.0.0.1:8080/upload](http://127.0.0.1:8080/upload)”, host: “192.168.0.127”, referrer: “[http://192.168.0.127/http/upload.html](http://192.168.0.127/http/upload.html)”

Your setup includes:  
client\_max\_body\_size 100m;

Do you also your php.ini configured to accommodate 100m files?  
Check:  
memory\_limit (should be something able to cope with 100M files)  
post\_max\_size (should be \>= 110M)  
file\_uploads (should be On)  
upload\_max\_filesize (should be \>= 100M)

Regards,  
M.

---

<div class="post-metadata">

**Author:** ![ppalka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/aeb1de/32.png) [@ppalka](https://www.ruby-forum.com/u/ppalka)\
**Post date:** [September 5, 2011, 11:34am UTC](https://www.ruby-forum.com/t/nginx-upload-module-v-2-2-0-502-bad-gateway/211474/3 "2011-09-05T11:34:10Z")

</div>

> Your setup includes:  
> client\_max\_body\_size 100m;
> 
> Do you also your php.ini configured to accommodate 100m files?  
> Check:  
> memory\_limit (should be something able to cope with 100M files)  
> post\_max\_size (should be \>= 110M)  
> file\_uploads (should be On)  
> upload\_max\_filesize (should be \>= 100M)

Thank you all for help!

I found the solution on this thread:  
[http://www.ruby-forum.com/topic/1432037](http://www.ruby-forum.com/topic/1432037)

The problem was that I did not wrote the form handler script.

This is my working configuration of nginx:

## /usr/local/nginx/conf/nginx.conf:

worker\_processes 20;

error\_log logs/error.log notice;

working\_directory /usr/local/nginx/html;

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 /my-form-handler;

         # 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$";
     }

    include fastcgi.conf;
    location = /my-form-handler {
       fastcgi_pass 127.0.0.1:9000;
     }

 }

```

## }

## /usr/local/nginx/html/my-form-handler
\<?php header("Content-Type: text/plain"); print("GET: "); print\_r($\_GET); print("POST: "); print\_r($\_POST); print("FILES: "); print\_r($\_FILES); ?\>
* * *

–  
best regards  
Piotr P.
