400 bad request nginx namecheap

Discussion in 'Linux' started by securityhope, Aug 29, 2016.

  1. securityhope

    securityhope Administrator Staff Member

    Joined:
    Aug 3, 2016
    Messages:
    1,241
    Likes Received:
    0
    Trophy Points:
    36
    I'm totally new at server things.

    I have an ip address from digitalocean. x.x.x.x
    I have a domain from namecheap. www.mywebsite.com

    I tried this:
    In Namecheap -> Manage Domains -> Modify Domain tab.
    Host name -> @ -> x.x.x.x -> Record Type (A)
    Host name -> www -> www.mywebsite.com -> Record Type (URL FRAME)

    I got 400 Bad Request message.

    And in DigitalOcean -> DNS tab i deleted all NSX.DIGITALOCEAN.COM. things.

    How can i synchronize these?

    Answer

    Probably I solved it.

    in Domain Name Server Setup -> First 3 line added NSX.DIGITALOCEAN.COM
    and
    in DigitalOcean -> Dns Tab Added NSX.DIGITALOCEAN.COM

    It's working, now.

    Namecheap DNS Causes Nginx 400

    Hey guys,

    I tried to use Namecheap's premium/basic DNS and it always produces a 400 bad request when I try loading the site. I added the A record etc in Namecheap and it still doesn't work.

    Answer

    Actually, looks like I needed to wait. All fine now.

    Forgot that I also changed the nameserver record in vestacp to the namecheap ones under DNS incase anyone has the same issue and is searching.

    Dealing with Nginx 400 Bad Request HTTP errors

    Some visitors reported that they were getting a "400 Bad Request" Nginx error randomly when visiting pages. And when they start getting that error, they can't access the site anymore: it'll output the same error no matter the page, until you "clear your cache and cookies".

    The error is easily understandable and is likely to be caused by... too much cookie data.
    Every time a visitor loads *any* page/content/file of your website, it sends the cookie data to the server.
    Cookie data is sent under the form of 1 header line starting with "Cookie: ".

    Basically, Nginx by default is configured to accept header lines of a maximum size of 4 kilobytes.
    When a line in the headers exceeds 4 kilobytes, Nginx returns the '400 Bad Request' error.
    Cookie data sometimes gets big, so it causes the error. It particularly happens on forums like vBulletin, Invision and others.
    So why does it happen only for some web browsers (Firefox, Chrome...) and not others? Because those browsers do not limit the amount of data a cookie may store. Or maybe they do, but the limit is higher than the default 4k of Nginx. Other browsers limit the amount of cookie data so they do not have the issue.

    There is a simple fix for that. The large_client_header_buffers directive of Nginx allows you to define size of buffers that will contain large headers like those big fat cookies.

    The directive specifies: the amount of buffers, and the size of buffers. You basically need to increase the size.
    In your http block (or your server block, if you want to apply the setting at the virtual host level), insert this directive with a size larger than 4k (actually the default size can be 8k depending on your system, so let's make it... 16k):

    Code:
    http {
       [...]
       large_client_header_buffers 4 16k;
       [...]
    }
    Save your configuration, reload nginx by running /usr/local/nginx/sbin/nginx -s reload and it should now be fine. If you ever get the "400 Bad Request" again, you could either increase this value once more or look into the code and see why cookies get so big.
     

Share This Page

Share