# Upload module can not upload file (Permission denied)

**URL:** <https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070>\
**Category:** NGINX\
**Created:** [March 28, 2011, 10:08pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070 "2011-03-28T22:08:48Z")\
**Posts on this page:** 10\
**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:** [March 28, 2011, 10:08pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/1 "2011-03-28T22:08:48Z")

</div>

Hi,  
I am trying to use upload moduel to upload file.  
I am following the instructions:  
[http://www.grid.net.ru/nginx/upload.en.html](http://www.grid.net.ru/nginx/upload.en.html)

However, I encountered “503 Service Temporarily Unavailable”.

When I looked at error.log, I have following messages:

47 2011/03/28 12:59:52 [notice] 16529#0: nginx/0.8.54  
48 2011/03/28 12:59:52 [notice] 16529#0: built by gcc 4.1.2 20080704  
(Red Hat 4.1.2-48)  
49 2011/03/28 12:59:52 [notice] 16529#0: OS: Linux 2.6.18-194.32.1.el5  
50 2011/03/28 12:59:52 [notice] 16529#0: getrlimit(RLIMIT\_NOFILE):  
1024:1024  
51 2011/03/28 12:59:52 [notice] 16530#0: start worker processes  
52 2011/03/28 12:59:52 [notice] 16530#0: start worker process 16531  
53 2011/03/28 13:00:01 [error] 16531#0: \*1 failed to create output file  
“/home/virus/tmp/0000000001” for “index. html” (13: Permission  
denied), client: 127.0.0.1, server: , request: “POST /upload HTTP/1.1”,  
host: “127.0.0. 1”, referrer: “[http://127.0.0.1/](http://127.0.0.1/)”

Even I use root to run the nginx, I still have the problem. I can  
“touch” the file in /home/virus/tmp directory.

Could anyone help me to figure out the issue?  
Thanks  
Yanxin

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 10:12pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/2 "2011-03-28T22:12:42Z")

</div>

> Even I use root to run the nginx, I still have the problem. I can  
> “touch” the file in /home/virus/tmp directory.

It’s only master process who starts with root, and this process  
initiates worker process started with permissions of user mentioned in  
nginx.conf.

–  
Regards, Vitaly T.  
System A.  
U.S. +1 (206) 905-9939  
Russia +7 911 094-2035

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 10:25pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/3 "2011-03-28T22:25:30Z")

</div>

Thank you for your help.

I changed chmod 777 for /tmp. The access issue is solved.  
However, I encountered another problem.

82 2011/03/28 13:19:11 [notice] 17231#0: start worker process 17232  
83 2011/03/28 13:19:20 [error] 17232#0: \*1 connect() failed (111:  
Connection refused) while connecting to upstream, client:  
127.0.0.1, server: , request: “POST /upload HTTP/1.1”, upstream:  
“[http://127.0.0.1:8080/](http://127.0.0.1:8080/) upload”, host: “127.0.0.1”, referrer:  
“[http://127.0.0.1/](http://127.0.0.1/)”

My configure file is here:  
1 worker\_processes 1;  
2  
3 error\_log logs/error.log notice;  
4  
5 working\_directory /opt/nginx;  
6  
7 events {  
8 worker\_connections 1024;  
9 }  
10  
11 http {  
12 include mime.types;  
13 default\_type application/octet-stream;  
14

15 server {  
16 listen 80;  
17 client\_max\_body\_size 100m;  
18  
19 location / {  
20 root html;  
21 index index.html;  
22 }  
23  
24 # Upload form should be submitted to this location  
25 location /upload {  
26 # Pass altered request body to this location  
27 upload\_pass @test;  
28  
29 # Store files to this directory  
30 # The directory is hashed, subdirectories 0 1 2 3 4 5 6  
7 8 9 should exist  
31 upload\_store /tmp;  
32  
33 # Allow uploaded files to be read only by user  
34 upload\_store\_access user:rw group:rw all:rw;  
35  
36 # Set specified fields in request body  
37 upload\_set\_form\_field “${upload\_field\_name}\_name”  
$upload\_file\_name;  
38 upload\_set\_form\_field  
“${upload\_field\_name}\_content\_type” $upload\_content\_type;  
39 upload\_set\_form\_field “${upload\_field\_name}\_path”  
$upload\_tmp\_path;  
40  
41 # Inform backend about hash and size of a file  
42 upload\_aggregate\_form\_field “${upload\_field\_name}\_md5”  
$upload\_file\_md5;  
43 upload\_aggregate\_form\_field “${upload\_field\_name}\_size”  
$upload\_file\_size;  
44  
45 upload\_pass\_form\_field “^submit$|^description$”;  
46 upload\_cleanup 400 404 499 500-505;  
47 }  
48  
49 # Pass altered request body to a backend  
50 location @test {  
51 #passenger\_enabled on;  
52 proxy\_pass [http://localhost:8080](http://localhost:8080);  
53 proxy\_temp\_path /home/virus/tmp/proxy\_temp;  
54 }  
55 }  
56 }

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 10:33pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/4 "2011-03-28T22:33:34Z")

</div>

No, I do not think I have 8080 server running.  
In the instruction, I do not see it start 8080 server first.

How to start 8080 upstream server? I see it is used by proxy\_pass,  
what’s the purpose of it?

Thanks,  
Yanxin

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 10:28pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/5 "2011-03-28T22:28:10Z")

</div>

On 3/29/2011 12:25 AM, Yanxin Z. wrote:

> “[http://127.0.0.1/](http://127.0.0.1/)”  
> Do you have another server running at 8080 on the same machine?

–  
Regards, Vitaly T.  
System A.  
U.S. +1 (206) 905-9939  
Russia +7 911 094-2035

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 10:41pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/6 "2011-03-28T22:41:46Z")

</div>

> 49 # Pass altered request body to a backend  
> 50 location @test {  
> 51 #passenger\_enabled on;  
> 52 proxy\_pass [http://localhost:8080](http://localhost:8080);  
> 53 proxy\_temp\_path /home/virus/tmp/proxy\_temp;  
> 54 }

It said here - pass request body to a backend. Since you don’t have  
backend running (proper application who will process request by that  
address) then nginx can’t pass it, then it fails. Nginx is fine.

–  
Regards, Vitaly T.  
System A.  
U.S. +1 (206) 905-9939  
Russia +7 911 094-2035

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 28, 2011, 11:43pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/7 "2011-03-28T23:43:58Z")

</div>

Hi Vitaly,  
I change my files a little bit. Let me start from beginning.

The file I have:  
conf/nginx.conf  
1 worker\_processes 1;  
2  
3 error\_log logs/error.log notice;  
4  
5 working\_directory /opt/nginx;  
6  
7 events {  
8 worker\_connections 1024;  
9 }  
10  
11 http {  
12 include mime.types;  
13 default\_type application/octet-stream;  
14  
15 server {  
16 listen 80;  
17 client\_max\_body\_size 100m;  
18  
19 # Upload form should be submitted to this location  
20 location /upload {  
21 # Pass altered request body to this location  
22 if ($request\_method = POST) {  
23 upload\_pass @test;  
24 break;  
25 }  
26  
27 # Store files to this directory  
28 # The directory is hashed, subdirectories 0 1 2 3 4 5 6  
7 8 9 should exist  
29 upload\_store /tmp;  
30  
31 # Allow uploaded files to be read only by user  
32 upload\_store\_access user:rw group:rw all:rw;  
33  
34 # Set specified fields in request body  
35 upload\_set\_form\_field “${upload\_field\_name}\_name”  
$upload\_file\_name;  
36 upload\_set\_form\_field  
“${upload\_field\_name}\_content\_type” $upload\_content\_type;  
37 upload\_set\_form\_field “${upload\_field\_name}\_path”  
$upload\_tmp\_path;  
38  
39 # Inform backend about hash and size of a file  
40 upload\_aggregate\_form\_field “${upload\_field\_name}\_md5”  
$upload\_file\_md5;  
41 upload\_aggregate\_form\_field “${upload\_field\_name}\_size”  
$upload\_file\_size;  
42  
43 upload\_pass\_form\_field “^submit$|^description$”;  
44 upload\_cleanup 400 404 499 500-505;  
45 }  
46  
47 # Pass altered request body to a backend  
48 location @test {  
49 proxy\_pass [http://localhost:8080](http://localhost:8080);  
50 }  
51 }  
52 }

/html/nginx.conf.default

1  
2 #user nobody;  
3 worker\_processes 1;  
4  
5 #error\_log logs/error.log;  
6 #error\_log logs/error.log notice;  
7 #error\_log logs/error.log info;  
8  
9 #pid logs/nginx.pid;  
10  
11  
12 events {  
13 worker\_connections 1024;  
14 }  
15  
16  
17 http {  
18 include mime.types;  
19 default\_type application/octet-stream;  
20  
21 #log\_format main '$remote\_addr - $remote\_user [$time\_local]  
“$request” ’  
22 # '$status $body\_bytes\_sent “$http\_referer” ’  
23 # ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;  
24  
25 #access\_log logs/access.log main;  
26  
27 sendfile on;  
28 #tcp\_nopush on;  
29  
30 #keepalive\_timeout 0;  
31 keepalive\_timeout 65;  
32  
33 #gzip on;  
34  
35 server {  
36 listen 8080;  
37 server\_name localhost;  
38  
39 #charset koi8-r;  
40  
41 #access\_log logs/host.access.log main;  
42  
43 location / {  
44 root html;  
45 index index.html index.htm;  
46 }  
47 }  
48 }

/html/upload.html

1   
2   
3 Test upload  
4   
5   
6

## Select files to upload
  
7   
8   
  
9   
  
10   
  
11   
  
12   
  
13   
  
14   
15   
16   
17   
18   
19

Then:  
I run nginx on 8080 and 80 port  
$/opt/nginx/sbin/nginx -c conf/nginx.conf.default  
$/opt/nginx/sbin/nginx

I got in the web browser:  
[http://127.0.0.1/upload.html](http://127.0.0.1/upload.html)

I see the form, select the file, and “upload”

Then I see “404 Not Found”.

The error.log shows:

2011/03/28 14:40:15 [error] 19402#0: \*2 open() “/opt/nginx/html/upload”  
failed (2: No such file or directory), client: 127.0.0.1, server:  
localhost, request: “POST /upload HTTP/1.0”, host: “localhost:8080”,  
referrer: “[http://127.0.0.1/upload.html](http://127.0.0.1/upload.html)”

I really do not know what should I do? It seems to me I missed the file  
upload. But I have no clue how to fix it.

Hopefully my explanation is clear to you.  
Thank you very much.  
Yanxin

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 29, 2011, 2:51am UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/8 "2011-03-29T02:51:43Z")

</div>

Hello,  
I finally realized  
I do not need to start backend server 8080 at all.

Although I still have error “502 Bad Gateway”

342 2011/03/28 17:47:44 [error] 30032#0: \*1 connect() failed (111:  
Connection refused) while connecting to upstream, client:  
127.0.0.1, server: , request: “POST /upload HTTP/1.1”, upstream:  
“[http://127.0.0](http://127.0.0). 1:8080/upload”, host: “127.0.0.1”, referrer:  
“[http://127.0.0.1/upload.html](http://127.0.0.1/upload.html)”

But the file is uploaded into /tmp already.

what a magic!!

BTW, how to fix this error then?

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 29, 2011, 6:11pm UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/9 "2011-03-29T18:11:01Z")

</div>

Thank you very much, Vitaly.

It’s working for me.  
Yanxin

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 29, 2011, 9:03am UTC](https://www.ruby-forum.com/t/upload-module-can-not-upload-file-permission-denied/205070/10 "2011-03-29T09:03:56Z")

</div>

On 3/29/2011 4:51 AM, Yanxin Z. wrote:

> what a magic!!  
> BTW, how to fix this error then?

If you need just to put file and not pass it anywhere try config listed  
in other thread:

[http://forum.nginx.org/read.php?21,186491](http://forum.nginx.org/read.php?21,186491)

It’s still not working, actually, but the thread didn’t started yet.  
Visit it later, and community will solve his problem.

–  
Regards, Vitaly T.  
System A.  
U.S. +1 (206) 905-9939  
Russia +7 911 094-2035
