2017-09-12 17 views
0

私はnginx問題があります。私はリバースプロキシとしてNGINXを、バックエンドとしてnodejを、DBとしてMongodbを使用しています。数日から、私は奇妙なエラーが出てきています。私はclient_max-body_sizeと10mを挿入しましたが、それでも問題を解決できませんでした。私が間違って 2017/09/11 23:46:40 [error] 39158#39158: *156474 client intended to send too large body: 3356812 bytes, client: 10.150.98.84, server: example.com, request: "POST /api/sensors HTTP/1.1", host: "example.com"Nginx Client_max_body_sizeは解決できません

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 from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for 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 to the static page /40x.html 
     # 
     error_page 404 /404.html; 
      location = /40x.html { 
     } 
     # redirect server error pages to the static page /50x.html 
     # 
     error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
     } 
} 
} 
+0

これを 'location/{'ブロックに追加できますか? –

+0

私には1つの質問があります。ですから、私は場所に追加する必要があります/ {ブロックし、他の場所からclient_max_body_size 10Mを削除します..? –

+0

リクエストが最初に着いてから '@ nodejs'でチェックされているので、私はそう信じているので、nodejsに到達する前に早く拒絶されています –

答えて

0

をしたところ、あなただけ受信することを期待大きな体とエンドポイントを公開し、この方法を/api/sensorsための特定の場所のブロックを追加して、同じ

location /api/sensors { 
    client_max_body_size 10M; 
    try_files dummy_file_not_exists @nodejs; 
} 

のための上限を増やす教えてくださいそれ。プロダクションを行う前に、ローカルでテストしてください。

+0

ありがとうございます。/api/sensorsの特定のブロックを追加せずに動作しますか?私は、/ api/sensorsのために余分なブロックを追加することが本当に必要かどうかということです。 –

+0

これは保護のようなものです。 'location /'に追加すると動作します。しかし、どのリソースを要求している間に10MBを送ることができるあなたの表面積を増加させます –

関連する問題