php+nginx 上傳大檔案 502 Bad Gateway

來源:互聯網
上載者:User
由於php每天要接收其它伺服器post過來的檔案
比如我在:192.168.1.147上用下面這條命令
wget http://192.168.1.148/upload.php --post-file=msg.log
這個msg.log 有50M,進行post msg.log這個檔案到148伺服器的php上儲存,進行入庫

首先說明:
不要問我怎麼不直接複製檔案,要用php接收?
我現在討論的是這個問題,謝謝。

原因:
首次調用出現了:
HTTP request sent, awaiting response... 413 Request Entity Too Large
我按照網上的教程改nginx配置
改為:
client_max_body_size 100m;
滿以為解決問題,再次執行報錯。
HTTP request sent, awaiting response... 502 Bad Gateway

網上有的說php.ini要配置,但是我的php.ini 配置是64M
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 128M 128M
open_basedir no value no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 64M 64M
upload_max_filesize 64M 64M

都找了好多,都是說配置php.ini, nginx.conf,還有php-fpm.conf的request_terminate_timeout=0,
最後沒用,自己試試就知道了,不多說了,多謝好人!

回複內容:

由於php每天要接收其它伺服器post過來的檔案
比如我在:192.168.1.147上用下面這條命令
wget http://192.168.1.148/upload.php --post-file=msg.log
這個msg.log 有50M,進行post msg.log這個檔案到148伺服器的php上儲存,進行入庫

首先說明:
不要問我怎麼不直接複製檔案,要用php接收?
我現在討論的是這個問題,謝謝。

原因:
首次調用出現了:
HTTP request sent, awaiting response... 413 Request Entity Too Large
我按照網上的教程改nginx配置
改為:
client_max_body_size 100m;
滿以為解決問題,再次執行報錯。
HTTP request sent, awaiting response... 502 Bad Gateway

網上有的說php.ini要配置,但是我的php.ini 配置是64M
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 128M 128M
open_basedir no value no value
output_buffering 4096 4096
output_handler no value no value
post_max_size 64M 64M
upload_max_filesize 64M 64M

都找了好多,都是說配置php.ini, nginx.conf,還有php-fpm.conf的request_terminate_timeout=0,
最後沒用,自己試試就知道了,不多說了,多謝好人!

nginx配置:    keepalive_timeout 600;     proxy_send_timeout 600;    client_max_body_size 200M;      fastcgi_connect_timeout 600;    fastcgi_send_timeout 600;    fastcgi_read_timeout 600;    fastcgi_buffer_size 1024k;    fastcgi_buffers 8 1024k;    fastcgi_busy_buffers_size 1024k;    fastcgi_temp_file_write_size 1024k;    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的配置或php-fpm上傳大小配置及post大小也需要修改

根據你的實際情況修改上邊的配置吧

具體原因不清楚, 不過502錯誤一般都是PHP那邊出了問題
不是沒響應,就是回應時間過長,等。
這裡已經和nginx沒什麼關係了

我在Xubuntu 14.04上用測試PHP CLI Server,只配置了下面兩條,其他都是預設配置,就能上傳90多MB的ZIP包了.

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();}?>

輸出:

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

同時本地測試了Nginx + PHP-FPM,Nginx只修改了下面這個配置:

client_max_body_size 128M;

經過我測試,上傳檔案是可以上傳成功的,但是我用wget --post-file 就返回502錯誤
wget可能有限制大檔案上傳,
用curl命令搞定:
curl -T "msg.log" "http://192.168.1.148/upload.php"
謝謝大家 結貼!

nginx_module_upload

你把php的執行時間調大一點,另外上傳逾時也調大一點。
set_time_limit(),max_input_time之類的。你是不是第一次調完後再上傳會等一會兒才報502錯?

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.