Reinis Rozitis
February 28, 2020 02:54AM
> I have added the below server block in /etc/nginx/nginx.conf (https://paste.centos.org/view/raw/d5e90b98)
>
> server {
> listen 80;
> server_name _;
> return 444;
> }
>
> When i try to run the below curl call, I am still receiving 200 OK response.

> #curl --verbose --header 'Host: www.example.com' https://developer-nonprod.example.com
> GET / HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.64.1
> Accept: */*

If you are testing 'https' then you have to add the 'listen 443;' to the catch all server{} block otherways it will only work for http requests.


Also your pasted configuration has:

server {
listen 80 default_server;

server_name developer-nonprod.example.com;
server_name_in_redirect off;
return 301 https://$host$request_uri;
}


server {
listen 80;
server_name _;
return 444;
}
}

In this case with non-defined Hosts (server_name's) the first server {} will be used since it has the default_server (and second is ignored) and you'll always get the redirect.

You could leave the existing http -> https redirect but then change the catch all to listen only on 443 .. so if there is no valid server_name definition the connection will be dropped.

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Prevent Arbitary HTTP Host header in nginx

kaushalshriyan February 27, 2020 01:36PM

RE: Prevent Arbitary HTTP Host header in nginx

Reinis Rozitis February 27, 2020 02:52PM

Re: Prevent Arbitary HTTP Host header in nginx

kaushalshriyan February 28, 2020 02:24AM

RE: Prevent Arbitary HTTP Host header in nginx

Reinis Rozitis February 28, 2020 02:54AM

Re: Prevent Arbitary HTTP Host header in nginx

kaushalshriyan February 28, 2020 03:24AM

RE: Prevent Arbitary HTTP Host header in nginx

Reinis Rozitis February 28, 2020 03:58AM

RE: Prevent Arbitary HTTP Host header in nginx

Reinis Rozitis February 28, 2020 04:00AM

Re: Prevent Arbitary HTTP Host header in nginx

kaushalshriyan February 28, 2020 05:00AM

RE: Prevent Arbitary HTTP Host header in nginx

Reinis Rozitis February 28, 2020 10:40AM

Re: Prevent Arbitary HTTP Host header in nginx

kaushalshriyan February 28, 2020 12:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready