configuration - Nginx Client_max_body_size not able to solve -
i have nginx issue. using nginx reverse proxy , nodejs backend , mongodb db. few days getting weird error says large body. inserted client_max-body_size , 10m, still couldn't able solve issue. please tell me did wrong 2017/09/11 23:46:40 [error] 39158#39158: *156474 client intended send large body: 3356812 bytes, client: 10.150.98.84, server: example.com, request: "post /api/sensors http/1.1", host: "example.com"
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; # load dynamic modules. see /usr/share/doc/nginx/readme.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # load modular configuration files /etc/nginx/conf.d directory. # see http://nginx.org/en/docs/ngx_core_module.html#include # more information. index index.html index.htm; upstream nodejs { server localhost:3000; } server { listen 80; server_name example.com; location / { if ($http_x_forwarded_proto != 'https') { return 301 https://$server_name$request_uri; } try_files $uri $uri/ @nodejs; } location @nodejs { proxy_redirect off; proxy_http_version 1.1; proxy_pass http://nodejs; proxy_set_header host $host ; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; client_max_body_size 10m; } location ~ (/images|/img|/javascript|/js|/css|/stylesheets|/flash|/media|/static|robots.txt|humans.txt|favicon.ico){ root /var/www/app/public; client_max_body_size 10m; } # redirect server error pages static page /40x.html # error_page 404 /404.html; location = /40x.html { } # redirect server error pages static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
add specific location block /api/sensors , increase limit same
location /api/sensors { client_max_body_size 10m; try_files dummy_file_not_exists @nodejs; } this way expose endpoint large body expects receive it. test locally before putting on production.
Comments
Post a Comment