Php + nginx upload large file 502 BadGateway

Source: Internet
Author: User
Tags php cli
Because php receives files post from other servers every day, for example, on 192.168.1.147, run the following command wget192.168.1.148upload. php -- post-filemsg.log This msg. if the log size is 50 MB, perform postmsg. log this file to the 148 server's ph... because php receives files post from other servers every day
For example, I used the following command on 192.168.1.147:
Wget http: // 192.168.1.148/upload. php -- post-file = msg. log
The msg. log is 50 MB, and the file "post msg. log" is stored in php on the 148 server for storage.

Note:
Don't ask me why I don't copy files directly. I want to use php to receive them?
I am discussing this question now. Thank you.

Cause:
The first call appears:
HTTP request sent, awaiting response... 413 Request Entity Too Large
I changed the nginx configuration according to the online tutorial.
Changed:
Client_max_body_size 100 m;
If the problem is solved, an error is reported again.
HTTP request sent, awaiting response... 502 Bad Gateway

Some people on the Internet say that php. ini needs to be configured, but my php. ini configuration is 64 M.
Max_execution_time 300 300
Max_file_uploads 20 20
Max_input_nesting_level 64 64
Max_input_time 60 60
Max_input_vars 1000 1000
Memory_limit 128 M 128 M
Open_basedir no value
Output_buffering 4096 4096
Output_handler no value
Post_max_size 64 M 64 M
Upload_max_filesize 64 M 64 M

Have found a lot, are said to configure php. ini, nginx. conf, And the php-fpm.conf request_terminate_timeout = 0,
It's useless at the end. I'll know it when I try it. I don't want to talk about it anymore. Thank you!

Reply content:

Because php receives files post from other servers every day
For example, I used the following command on 192.168.1.147:
Wget http: // 192.168.1.148/upload. php -- post-file = msg. log
The msg. log is 50 MB, and the file "post msg. log" is stored in php on the 148 server for storage.

Note:
Don't ask me why I don't copy files directly. I want to use php to receive them?
I am discussing this question now. Thank you.

Cause:
The first call appears:
HTTP request sent, awaiting response... 413 Request Entity Too Large
I changed the nginx configuration according to the online tutorial.
Changed:
Client_max_body_size 100 m;
If the problem is solved, an error is reported again.
HTTP request sent, awaiting response... 502 Bad Gateway

Some people on the Internet say that php. ini needs to be configured, but my php. ini configuration is 64 M.
Max_execution_time 300 300
Max_file_uploads 20 20
Max_input_nesting_level 64 64
Max_input_time 60 60
Max_input_vars 1000 1000
Memory_limit 128 M 128 M
Open_basedir no value
Output_buffering 4096 4096
Output_handler no value
Post_max_size 64 M 64 M
Upload_max_filesize 64 M 64 M

Have found a lot, are said to configure php. ini, nginx. conf, And the php-fpm.conf request_terminate_timeout = 0,
It's useless at the end. I'll know it when I try it. I don't want to talk about it anymore. Thank you!

Nginx configuration: keepalive_timeout 600; proxy_send_timeout 600; Memory 200 M; fastcgi_connect_timeout 600; fastcgi_send_timeout 600; Memory 600; Memory 1024 k; fastcgi_buffers 8 1024 k; Memory 1024 k; Memory 1024 k; proxy_ignore_client_abort on; tcp_nopush on; tcp_nodelay on; client_header_timeout 600; client_body_timeout 600; sendfile on; send_timeout 600;

Php configuration or php-fpm upload size configuration and post size also need to be modified

Modify the above configuration according to your actual situation.

The specific cause is unclear, but the error 502 is usually caused by a problem in PHP.
Either no response or long response time.
It has nothing to do with nginx.

I tested php cli Server on Xubuntu 14.04 and configured only the following two items. The others are default configurations, so that I can upload a ZIP package of more than 90 MB.

upload_max_filesize=100Mpost_max_size=128M
php -S 127.0.0.1:8080 -t /png/www/example.com/public_html/// chmod 777 /png/www/example.com/public_html/app/yab/static/// http://127.0.0.1:8080/app/yab/upload.php
  ';    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {        echo "File is valid, and was successfully uploaded.\n";    } else {        echo "Possible file upload attack!\n";    }    echo 'Here is some more debugging info:';    print_r($_FILES);    print "
"; exit();}?>

Output:

File is valid, and was successfully uploaded.Here is some more debugging info:Array(    [userfile] => Array        (            [name] => firefox.zip            [type] => application/zip            [tmp_name] => /tmp/phpG1PdtU            [error] => 0            [size] => 93938426        ))

At the same time locally tested Nginx + PHP-FPM, Nginx only modified the following Configuration:

client_max_body_size 128M;

After my tests, the file can be uploaded successfully, but I use wget -- post-file to Return Error 502.
Wget may restrict uploading of large files,
Run the curl command:
Curl-T "msg. log" "http: // 192.168.1.148/upload. php"
Thank you for your posting!

Nginx_module_upload

You can increase the php Execution time and upload time-out.
Set_time_limit (), max_input_time, and so on. Are you sure you want to report the 502 error only after the first upload?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.