php+nginx 上传大文件 502 Bad Gateway
由于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,
最后没用,自己试试就知道了,不多说了,多谢好人!
<code>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; </code>
php的配置或php-fpm上传大小配置及post大小也需要修改
根据你的实际情况修改上边的配置吧
具体原因不清楚, 不过502错误一般都是PHP那边出了问题
不是没响应,就是响应时间过长,等。
这里已经和nginx没什么关系了
我在Xubuntu 14.04上用测试PHP CLI Server,只配置了下面两条,其他都是默认配置,就能上传90多MB的ZIP包了.
<code>upload_max_filesize=100M post_max_size=128M </code>
<code>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 <?php if(!empty($_FILES)){ $uploaddir = '/png/www/example.com/public_html/app/yab/static/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo '<pre class="brush:php;toolbar:false">'; 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 "</code>
输出:
<code>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 ) ) </code>
同时本地测试了Nginx + PHP-FPM,Nginx只修改了下面这个配置:
<code>client_max_body_size 128M; </code>
经过我测试,上传文件是可以上传成功的,但是我用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错?

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

在 Linux 中启动 Nginx 的步骤:检查 Nginx 是否已安装。使用 systemctl start nginx 启动 Nginx 服务。使用 systemctl enable nginx 启用在系统启动时自动启动 Nginx。使用 systemctl status nginx 验证启动是否成功。在 Web 浏览器中访问 http://localhost 查看默认欢迎页面。

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

启动 Nginx 服务器需要按照不同操作系统采取不同的步骤:Linux/Unix 系统:安装 Nginx 软件包(例如使用 apt-get 或 yum)。使用 systemctl 启动 Nginx 服务(例如 sudo systemctl start nginx)。Windows 系统:下载并安装 Windows 二进制文件。使用 nginx.exe 可执行文件启动 Nginx(例如 nginx.exe -c conf\nginx.conf)。无论使用哪种操作系统,您都可以通过访问服务器 IP

服务器无权访问所请求的资源,导致 nginx 403 错误。解决方法包括:检查文件权限。检查 .htaccess 配置。检查 nginx 配置。配置 SELinux 权限。检查防火墙规则。排除其他原因,如浏览器问题、服务器故障或其他可能的错误。

如何解决 Nginx 403 Forbidden 错误?检查文件或目录权限;2. 检查 .htaccess 文件;3. 检查 Nginx 配置文件;4. 重启 Nginx。其他可能原因还包括防火墙规则、SELinux 设置或应用程序问题。

在 Linux 中,使用以下命令检查 Nginx 是否已启动:systemctl status nginx根据命令输出进行判断:如果显示 "Active: active (running)",则 Nginx 已启动。如果显示 "Active: inactive (dead)",则 Nginx 已停止。

解决 Nginx 跨域问题有两种方法:修改跨域响应头:添加指令以允许跨域请求,指定允许的方法和头,以及设置缓存时间。使用 CORS 模块:启用模块并配置 CORS 规则,允许跨域请求、方法、头和设置缓存时间。
