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
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/”
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
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
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/ upload”, host: “127.0.0.1”, referrer:
“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;
53 proxy_temp_path /home/virus/tmp/proxy_temp;
54 }
55 }
56 }
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
On 3/29/2011 12:25 AM, Yanxin Z. wrote:
“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
49 # Pass altered request body to a backend
50 location @test {
51 #passenger_enabled on;
52 proxy_pass 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
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;
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
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”
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
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. 1:8080/upload”, host: “127.0.0.1”, referrer:
“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?
Thank you very much, Vitaly.
It’s working for me.
Yanxin
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:
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