NGINX invalid gateway 502, upstream sent too big header

Hi, I have a problem I never encountered before:
[error] 26#26: *147 upstream sent too big header while reading response header from upstream, client: 192.168.0.3, server: localhost, request: "GET /xxxxx/xxxxxxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxxxx-xxxxxxxxxx.up.railway.app"
[error] 26#26: *147 upstream sent too big header while reading response header from upstream, client: 192.168.0.3, server: localhost, request: "GET /xxxxx/xxxxxxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxxxx-xxxxxxxxxx.up.railway.app"
This is using the Nixpacks, so I dont think I can edit the nginx.conf file, if this only solvable by using docker, could someone guide me trough it, I never used docker, but my github repo of this project is open so anyone could take a look at it! Its boilerplate material right now, but I want to make a game with Vue and Laravel. https://github.com/GILLESMaster/Krilinga Project ID (e54f7042-71b3-4bc4-b530-c2d41b9cad7c) πŸ™ Thx in advance!
Solution:
you actually can provide your own nginx config https://nixpacks.com/docs/providers/php...
Jump to solution
13 Replies
Percy
Percyβ€’2y ago
Project ID: e54f7042-71b3-4bc4-b530-c2d41b9cad7c
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
Other pages work Altough you can get to this page, refreshing will result in 502 bad gateway with the
[error] 26#26: *147 upstream sent too big header while reading response header from upstream, client: 192.168.0.3, server: localhost, request: "GET /xxxxx/xxxxxxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxxxx-xxxxxxxxxx.up.railway.app"
[error] 26#26: *147 upstream sent too big header while reading response header from upstream, client: 192.168.0.3, server: localhost, request: "GET /xxxxx/xxxxxxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxxxx-xxxxxxxxxx.up.railway.app"
error
Solution
Brody
Brodyβ€’2y ago
you actually can provide your own nginx config https://nixpacks.com/docs/providers/php
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
omg facepalm THX I will mark this resolved unless it didnt fix it! πŸ‘
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
I might have mistyped something kekw Ironic commit desc lol
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
@Brody doesnt work, even the template nginx.conf https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
Brody
Brodyβ€’2y ago
where have you changed the max header size?
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
Is under
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}
in
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
#include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
#include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
@Brody nginx: [emerg] host not found in "${PORT}" of the "listen" directive in /app/nginx.conf:25 this also gave me errors
include $!{nginx}/conf/mime.types;
include $!{nginx}/conf/mime.types;
I think the placeholders dont get updated? I fixed the mime.types by using a custom one in the root dir and pointing to that but how do I asign the random port each time?
𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
my latest change:
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include mime.types; #works
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT}; # <- throws error
listen [::]:${PORT}; # <- prob also throws error if line is reached
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params; # <- this one broken?
include $!{nginx}/conf/fastcgi.conf; # <- this one maybe broken aswell
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include mime.types; #works
index index.html index.htm index.php;

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; # this seems to be required for some vhosts

server {
listen ${PORT}; # <- throws error
listen [::]:${PORT}; # <- prob also throws error if line is reached
server_name localhost;

$if(NIXPACKS_PHP_ROOT_DIR) (
root ${NIXPACKS_PHP_ROOT_DIR};
) else (
root /app;
)

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

$if(IS_LARAVEL) (
location / {
try_files $uri $uri/ /index.php?$query_string;
}
) else ()

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

$if(IS_LARAVEL) (
error_page 404 /index.php;
) else ()

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params; # <- this one broken?
include $!{nginx}/conf/fastcgi.conf; # <- this one maybe broken aswell
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
brb, ping me when needed! I have tried many things, still nothing works,
worker_processes auto;
daemon off;

events {
worker_connections 1024;
}

http {
include mime.types;
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; # this seems to be required for some vhosts
keepalive_timeout 65;

server {
listen 0.0.0.0:80;
listen [::]:80;
server_name localhost;

root /app/public;
index index.php index.html;

charset utf-8;

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;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes auto;
daemon off;

events {
worker_connections 1024;
}

http {
include mime.types;
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; # this seems to be required for some vhosts
keepalive_timeout 65;

server {
listen 0.0.0.0:80;
listen [::]:80;
server_name localhost;

root /app/public;
index index.php index.html;

charset utf-8;

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;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
😭
Brody
Brodyβ€’2y ago
its very odd that its not getting escaped, ive used that template without issues myself oh i see when you use a template nginx config it needs to be specifically named nginx.template.conf but you just have it named nginx.conf therefore its not being treated as a template @𝔾𝕦𝕀π•₯𝕒𝕧𝕠 π•Šπ•”π•™π•šπ•‘
Brody
Brodyβ€’2y ago
awesome!! glad I could help πŸ™‚
Want results from more Discord servers?
Add your server