I'm encountering an issue with PHP and Nginx when handling large file return via an API.
Issue:
Small files (under 2GB) are processed correctly. Large files result in an empty response with a 200 status code.
Configuration:
- php.ini:
- post_max_size = 800 -> 4000
- upload_max_filesize = 2000 -> 4000
- nginx.conf:
- client_max_body_size = 300 -> 4000
- memory_limit = -1
Restart procedure:
sudo php-fpm8.3 -t
sudo service php8.3-fpm
sudo systemctl reload nginx
Verified the configuration was applied (php -i).
Error logs:
Checked logs (/var/log/nginx/error.log), but found no errors.
What could be causing the issue?
- Adjusted php.ini settings (post_max_size, upload_max_filesize, memory_limit).
- Modified nginx.conf (client_max_body_size).
- Restarted PHP-FPM and Nginx.
- Checked logs (/var/log/nginx/error.log).
What I Expected:
Large files (over 2GB) should be processed and returned correctly.
I'm encountering an issue with PHP and Nginx when handling large file return via an API.
Issue:
Small files (under 2GB) are processed correctly. Large files result in an empty response with a 200 status code.
Configuration:
- php.ini:
- post_max_size = 800 -> 4000
- upload_max_filesize = 2000 -> 4000
- nginx.conf:
- client_max_body_size = 300 -> 4000
- memory_limit = -1
Restart procedure:
sudo php-fpm8.3 -t
sudo service php8.3-fpm
sudo systemctl reload nginx
Verified the configuration was applied (php -i).
Error logs:
Checked logs (/var/log/nginx/error.log), but found no errors.
What could be causing the issue?
- Adjusted php.ini settings (post_max_size, upload_max_filesize, memory_limit).
- Modified nginx.conf (client_max_body_size).
- Restarted PHP-FPM and Nginx.
- Checked logs (/var/log/nginx/error.log).
What I Expected:
Large files (over 2GB) should be processed and returned correctly.
Share Improve this question edited 13 hours ago VLAZ 29.1k9 gold badges62 silver badges84 bronze badges asked yesterday seeun choiseeun choi 11 New contributor seeun choi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 6 | Show 1 more comment1 Answer
Reset to default -1PHP/Nginx Large File Handling Configuration
This guide provides a comprehensive solution for handling large file uploads (>2GB) through PHP and Nginx APIs.
Common Issues
- Empty response with 200 status code for files >2GB
- Timeout during upload process
- Memory exhaustion
- Incomplete file transfers
Server Configuration
PHP Configuration (php.ini)
; File upload limits
post_max_size = 4000M
upload_max_filesize = 4000M
memory_limit = -1
; Timeouts
max_execution_time = 300
max_input_time = 300
; Buffer settings
output_buffering = Off
zlib.output_compression = Off
; Error reporting for debugging
error_reporting = E_ALL
display_errors = On
log_errors = On
Nginx Configuration (nginx.conf)
http {
# Client body size
client_max_body_size 4000M;
# Timeouts
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
proxy_read_timeout 300;
# Buffer sizes
client_body_buffer_size 128k;
client_header_buffer_size 1k;
}
PHP-FPM Configuration
; Timeout settings
request_terminate_timeout = 300
; Slow log configuration
slowlog = /var/log/php-fpm/slow.log
request_slowlog_timeout = 60
max_input_time = 6000
,max_execution_time = 6000
, andmemory_limit = -1
in thephp.ini
file. Also, make sure you have set theclient_max_body_size
in both theHTTP block
and theserver block
in thenginx.conf
file. – Kamyar Safari Commented yesterday}
AND Have you also restarted nginx and fpm? ` sudo service php8.3-fpm restart ` ` sudo service nginx restart ` – Kamyar Safari Commented yesterday