File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,14 @@ server {
1010 listen 80;
1111 server_name {{ nginx_server_name }};
1212 server_tokens off;
13+
14+ # Terminate the request immediately if a request uses the IP address.
15+ # This stops Invalid HTTP_HOST header exceptions being raised by Django.
16+
17+ if ($host !~* ^({{ nginx_server_name }})$ ) {
18+ return 444;
19+ }
20+
1321 return 301 https://$server_name$request_uri;
1422}
1523
@@ -31,6 +39,13 @@ server {
3139 ssl_dhparam /etc/ssl/certs/dhparams.pem;
3240 {% endif %}
3341
42+ # Terminate the request immediately if a request uses the IP address.
43+ # This stops Invalid HTTP_HOST header exceptions being raised by Django.
44+
45+ if ($host !~* ^({{ nginx_server_name }})$ ) {
46+ return 444;
47+ }
48+
3449 # Prevent MIME type sniffing for security
3550 add_header X-Content-Type-Options "nosniff";
3651
@@ -95,7 +110,7 @@ server {
95110
96111 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
97112 proxy_set_header X-Forwarded-Proto https;
98- proxy_set_header Host $http_host ;
113+ proxy_set_header Host $host ;
99114 proxy_redirect off;
100115
101116 # Try to serve static files from nginx, no point in making an
You can’t perform that action at this time.
0 commit comments