4 days ago
Hi Railway team,
I'm getting a "413 Content Too Large" error when uploading files >1MB to my Laravel PHP API. My PHP settings are correctly configured (100M upload limit), but nginx appears to have a 1MB limit.
What I've already tried:
Environment variables approach
(PHP side working):
PHP_UPLOAD_MAX_FILESIZE=100M
PHP_POST_MAX_SIZE=120M
PHP_MAX_EXECUTION_TIME=300
PHP_MEMORY_LIMIT=256M
Custom nginx.conf file
(deployment failed):
Created nginx.conf with client_max_body_size 100M;
Modified nixpacks.toml with custom start command
Result: nginx errors about missing /etc/nginx/mime.types and PHP-FPM configuration conflicts
Different nginx.conf configurations
(deployment failed):
Tried various nginx.conf structures (with http blocks, minimal configs, etc.)
Result: Multiple errors including "client_max_body_size" directive is not allowed here and PHP-FPM initialization failures
The custom configuration approaches break the deployment because they interfere with Nixpacks' built-in nginx and PHP-FPM setup.
Request: Can you help me increase the nginx client_max_body_size to 100M for my service tenderr-be-production using Railway's recommended method? Is there a built-in environment variable like NGINX_CLIENT_MAX_BODY_SIZE that I should use, or do you have a working nginx.conf template specifically for Nixpacks PHP deployments?
Current setup:
Laravel PHP 8.1 app
Using Nixpacks
Thanks for your help!
3 Replies
4 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
4 days ago
hi, to raise nginx’s upload limit on railway, you need to adjust the client_max_body_size in your custom nginx config and redeploy. you can do it like this:
server {
client_max_body_size 100m;
…
}
or include it under the http block to apply site-wide. then redeploy so nginx picks it up. if you’re using PHP, also bump upload_max_filesize and post_max_size in php.ini to at least the same limit. restart or redeploy after making those changes.
3 days ago
PHP file upload limits are still not being applied despite multiple configuration attempts, causing large file uploads to fail silently.
THE SOLUTION:
nixpacks.toml file:
[variables]
NIXPACKS_PHP_ROOT_DIR = '/app/public'
UPLOAD_MAX_FILESIZE = '150M'
POST_MAX_SIZE = '150M'
[phases.setup]
nixPkgs = ["postgresql", "gd", "libsodium", "php81", "php81Packages.composer", "nodejs", "nginx"]
cmds = ['UPLOAD_INI_PATH=$(find /nix/store/*-php-*/lib -name php.ini -print0 | tail -z -n 1 | rev | cut -c 9- | rev)/upload.ini; echo "upload_max_filesize=${UPLOAD_MAX_FILESIZE};" >> $UPLOAD_INI_PATH; echo "post_max_size=${POST_MAX_SIZE};" >> $UPLOAD_INI_PATH']
The most important thing is having the | tail -z -n 1 | as one of the commands inside the array of cmds as that specifies for nixpacks that it should look for the last config (the tail one) and not the first one (head)
this one you can modify a bit as I have but I'm pasting it because of the structure, the name of the file is really important. And I bolded out the important stuff:
nginx.template.conf file:
worker_processes auto;
daemon off;
worker_rlimit_nofile 8192;
events {
worker_connections 4096;
}
http {
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128;
# File upload settings
client_max_body_size 1200M;
client_body_timeout 300s;
client_header_timeout 300s;
# Buffering for large uploads
client_body_buffer_size 128k;
client_body_temp_path /tmp/nginx_uploads;
server {
listen ${PORT};
server_name localhost;
root ${NIXPACKS_PHP_ROOT_DIR};
index index.php;
charset utf-8;
# Timeout settings for large uploads
keepalive_timeout 300s;
send_timeout 300s;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
# FastCGI timeout settings
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
Status changed to Solved chandrika • 3 days ago