Question

nginx throws Bad Request (400)

I get this error when I attempt to access my site at: http://exhibit.technology

**The Webconfs header check tool shows the following.

`HTTP/1.1 400 Bad Request =>
Server => nginx/1.14.0 (Ubuntu)
Date => Sun, 23 Apr 2023 20:24:50 GMT
Content-Type => text/html
Connection => close
X-Content-Type-Options => nosniff
Referrer-Policy => same-origin**

The IP address of the above URL is 192.81.211.160. When I enter it directly it works. My site loads. http://192.81.211.160

The Webconfs header check tool shows:

HTTP/1.1 200 OK =>
Server => nginx/1.14.0 (Ubuntu)
Date => Sun, 23 Apr 2023 20:23:35 GMT
Content-Type => text/html; charset=utf-8
Content-Length => 6857
Connection => close
X-Frame-Options => DENY
Vary => Cookie
X-Content-Type-Options => nosniff
Referrer-Policy => same-origin

The nginx error log (the lines around the report of the HTTP 400 error) is shown below (I can provide more if needed).

I do not see why the IP address access works but the name access does not. Also, I do not know how to infer the problem from the log. Any help appreciated.

The DNS and hosting is on Digital Ocean. The app. is written in Django and has Debug=False and ALLOWED_HOSTS populated in settings.py

nginx log:

023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream dummy handler
2023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream request: "/?"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream dummy handler
2023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream request: "/?"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream process header
2023/04/23 20:42:39 [debug] 13352#13352: *2 malloc: 000056424E53BD20:4096
2023/04/23 20:42:39 [debug] 13352#13352: *2 recv: eof:0, avail:1
2023/04/23 20:42:39 [debug] 13352#13352: *2 recv: fd:12 190 of 4096
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy status 400 "400 Bad Request"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "Server: gunicorn"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "Date: Sun, 23 Apr 2023 20:42:39 GMT"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "Connection: close"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "Content-Type: text/html"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "X-Content-Type-Options: nosniff"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header: "Referrer-Policy: same-origin"
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy header done
2023/04/23 20:42:39 [debug] 13352#13352: *2 xslt filter header
2023/04/23 20:42:39 [debug] 13352#13352: *2 HTTP/1.1 400 Bad Request
Server: nginx/1.14.0 (Ubuntu)
Date: Sun, 23 Apr 2023 20:42:39 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin

2023/04/23 20:42:39 [debug] 13352#13352: *2 write new buf t:1 f:0 000056424E567A58, pos 000056424E567A58, size: 236 file: 0, size: 0
2023/04/23 20:42:39 [debug] 13352#13352: *2 http write filter: l:0 f:0 s:236
2023/04/23 20:42:39 [debug] 13352#13352: *2 http cacheable: 0
2023/04/23 20:42:39 [debug] 13352#13352: *2 posix_memalign: 000056424E53CD30:4096 @16
2023/04/23 20:42:39 [debug] 13352#13352: *2 http proxy filter init s:400 h:0 c:0 l:-1
2023/04/23 20:42:39 [debug] 13352#13352: *2 http upstream process upstream
2023/04/23 20:42:39 [debug] 13352#13352: *2 pipe read upstream: 0
2023/04/23 20:42:39 [debug] 13352#13352: *2 pipe preread: 0
202

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 11, 2023

Hi there,

From your logs, it seems like the problem lies with the gunicorn application server which is returning a 400 Bad Request error. Gunicorn is likely having trouble processing the request from Nginx when the domain name is used.

I’ve seen this problem when the ALLOWED_HOSTS in Django settings.py file does not include the domain name.

Try adding ‘exhibit.technology’ to ALLOWED_HOSTS list in your settings.py file and see if that resolves the issue.

Here’s an example of how to do it:

ALLOWED_HOSTS = ['192.81.211.160', 'exhibit.technology']

Remember to restart your Django application after making changes to the settings.py file.

If your issue still persists, please share the relevant parts of your Nginx configuration and the command or service file you are using to start Gunicorn. With that information, we could give you a more detailed answer.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel