I have my site which is using nginx, and testing site with header testing tools e.g. http://www.webconfs.com/http-header-check.php but every time it says 400 bad request below is the out put from the tool. Though all my pages load perfectly fine in browser and when I see in chrome console it says status code 200OK.
HTTP/1.1 400 Bad Request => Server => nginx Date => Fri, 07 Sep 2012 09:40:09 GMT Content-Type => text/html Content-Length => 166 Connection => close
I really don't understand what is the problem with my server config?
A bit of googling suggests to increase the buffer size using, and I increased it to following:
large_client_header_buffers 4 16k;
The same results persist.
Can some one guide me to the right direction?
As stated by Maxim Dounin in the comments above:
When nginx returns 400 (Bad Request) it will log the reason into error log, at "info" level. Hence an obvious way to find out what's going on is to configure error_log to log messages at "info" level and take a look into error log when testing.
Yes changing the error_to debug level as Emmanuel Joubaud suggested worked out (edit /etc/nginx/sites-enabled/default ):
error_log /var/log/nginx/error.log debug;
Then after restarting nginx I got in the error log with my Python application using uwsgi:
2017/02/08 22:32:24 [debug] 1322#1322: *1 connect to unix:///run/uwsgi/app/socket, fd:20 #2 2017/02/08 22:32:24 [debug] 1322#1322: *1 connected 2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream connect: 0 2017/02/08 22:32:24 [debug] 1322#1322: *1 posix_memalign: 0000560E1F25A2A0:128 @16 2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream send request 2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream send request body 2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer buf fl:0 s:454 2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer in: 0000560E1F2A0928 2017/02/08 22:32:24 [debug] 1322#1322: *1 writev: 454 of 454 2017/02/08 22:32:24 [debug] 1322#1322: *1 chain writer out: 0000000000000000 2017/02/08 22:32:24 [debug] 1322#1322: *1 event timer add: 20: 60000:1486593204249 2017/02/08 22:32:24 [debug] 1322#1322: *1 http finalize request: -4, "/?" a:1, c:2 2017/02/08 22:32:24 [debug] 1322#1322: *1 http request count:2 blk:0 2017/02/08 22:32:24 [debug] 1322#1322: *1 post event 0000560E1F2E5DE0 2017/02/08 22:32:24 [debug] 1322#1322: *1 post event 0000560E1F2E5E40 2017/02/08 22:32:24 [debug] 1322#1322: *1 delete posted event 0000560E1F2E5DE0 2017/02/08 22:32:24 [debug] 1322#1322: *1 http run request: "/?" 2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream check client, write event:1, "/" 2017/02/08 22:32:24 [debug] 1322#1322: *1 http upstream recv(): -1 (11: Resource temporarily unavailable)
Then I took a look to my uwsgi log and found out that:
Invalid HTTP_HOST header: 'www.mysite.local'. You may need to add u'www.mysite.local' to ALLOWED_HOSTS. [pid: 10903|app: 0|req: 2/4] 192.168.221.2 () {38 vars in 450 bytes} [Wed Feb 8 22:32:24 2017] GET / => generated 54098 bytes in 55 msecs (HTTP/1.1 400) 4 headers in 135 bytes (1 switches on core 0)
And adding www.mysite.local to the settings.py ALLOWED_HOSTS fixed the issue :)
ALLOWED_HOSTS = ['www.mysite.local']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With