복붙노트

[RUBY-ON-RAILS] 400 잘못된 요청 - 요청 헤더 너무 큰 쿠키

RUBY-ON-RAILS

400 잘못된 요청 - 요청 헤더 너무 큰 쿠키

내 레일 응용 프로그램과 함께 400 잘못된 요청 요청 헤더 또는의 nginx에서 너무 큰 쿠키를 얻고있다. 브라우저를 다시 시작하면 문제를 해결합니다. 이 작은해야한다, 그래서 나는 단지 내 쿠키에 문자열 ID를 저장하고있다.

어디의 nginx 오류 로그를 찾을 수 있습니까? 나는 나노 /opt/nginx/logs/error.log 보았다,하지만 아무 관련이 없습니다.

나는 세트 다음과 행운을 시도했다 :

location / {
    large_client_header_buffers  4 32k;
    proxy_buffer_size  32k;
}

nginx.conf

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
  worker_connections  1024;
}
http {
passenger_root /home/app/.rvm/gems/ruby-1.9.3-p392/gems/passenger-3.0.19;
passenger_ruby /home/app/.rvm/wrappers/ruby-1.9.3-p392/ruby;
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
client_max_body_size 20M;
server {
    listen       80;
    server_name  localhost;
    root /home/app/myapp/current/public;
    passenger_enabled on;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;

# location / {
#   large_client_header_buffers  4 32k;
#   proxy_buffer_size  32k;
# }

     #  location / {
     #   root   html;
     #   index  index.html index.htm;
     #   client_max_body_size 4M;
#   client_body_buffer_size 128k;
# }
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443;
#    server_name  localhost;

#    ssl                  on;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers   on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

다음은 쿠키와 방화범에있는 쿠키의 스크린 샷을 저장하는 내 코드입니다. 나는 저장된 세션을 확인하기 위해 불을 지르고를 사용하고 난 새로운 유물과 jQuery를 너무 쿠키를 저장하는 발견; 쿠키 크기를 초과 이유가 될 수 있을까?

def current_company
  return if current_user.nil?
  session[:current_company_id] = current_user.companies.first.id if session[:current_company_id].blank?
    @current_company ||= Company.find(session[:current_company_id])
end

해결법

  1. ==============================

    1.요청 헤더 또는 쿠키 너무 대형 - 그것은 오류가 말한다 단지거야. 당신의 헤더 중 하나는 정말 큰이며,의 nginx는 그것을 거부한다.

    요청 헤더 또는 쿠키 너무 대형 - 그것은 오류가 말한다 단지거야. 당신의 헤더 중 하나는 정말 큰이며,의 nginx는 그것을 거부한다.

    당신은 large_client_header_buffers과 올바른 궤도에있어. 당신이 문서를 선택하면, 당신은 HTTP 또는 서버 컨텍스트에서만 유효입니다 찾을 수 있습니다. 서버 블록에 볼륨을 높이 그것은 작동합니다.

    server {
        # ...
        large_client_header_buffers 4 32k;
        # ...
    }
    

    나쁜 헤더는 8192 바이트 이상의 것이어야하므로 그런데, 기본 버퍼 수와 크기는 4 8K입니다. 귀하의 경우에는, (하나의 헤더에 결합) 모든 쿠키 한도를 초과 잘됩니다. 특히 그 mixpanel 쿠키는 매우 커질.

  2. ==============================

    2.추가하여 고정

    추가하여 고정

    server {
      ...
      large_client_header_buffers 4 16k;
      ...
    } 
    
  3. ==============================

    3.위의 답변에 대해, 함께하지만, 언급 할 client_header_buffer_size 필요가있다 :

    위의 답변에 대해, 함께하지만, 언급 할 client_header_buffer_size 필요가있다 :

    http {
      ...
      client_body_buffer_size     32k;
      client_header_buffer_size   8k;
      large_client_header_buffers 8 64k;
      ...
    }
    
  4. ==============================

    4.내 경우 (클라우드 파운드리 / Nginx에의 buildpack)에서는 이유는 지시 proxy_set_header 호스트이었다 ... 안정되었다 nginx를이 줄을 제거한 후 :

    내 경우 (클라우드 파운드리 / Nginx에의 buildpack)에서는 이유는 지시 proxy_set_header 호스트이었다 ... 안정되었다 nginx를이 줄을 제거한 후 :

    http {
      server {
        location /your-context/ {
           # remove it: # proxy_set_header Host myapp.mycfdomain.cloud;
        }
      }
    }
    
  5. from https://stackoverflow.com/questions/17524396/400-bad-request-request-header-or-cookie-too-large by cc-by-sa and MIT license