<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020 at 9:08 PM Reinis Rozitis <<a href="mailto:r@roze.lv">r@roze.lv</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> I did follow your steps. My nginx.conf file is <a href="https://paste.centos.org/view/ae22889e" rel="noreferrer" target="_blank">https://paste.centos.org/view/ae22889e</a> when I run the curl call, I am still receiving HTTP 200 OK response instead of HTTP 444 (No Response) as per the below output<br>
<br>
If you've just called config reload then most likely your nginx is still using an old configuration (you should always check with: nginx -t).<br>
<br>
<br>
I tried to make a simple test case and turns out you can't have just 'listen 443;' directive (even there is no 'ssl' option) in one server block if another has ' listen 443 ssl;' nginx requires to specify a "ssl_certificate" (which is kind of understandable if you know that nginx has several caveats regarding listen ip:port pairs).<br>
<br>
The error looks like:<br>
<br>
nginx -t<br>
nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in nginx.conf:39<br>
nginx: configuration file nginx.conf test failed<br>
<br>
So before writing solutions out of head one should always note that and/or test your own suggestions :)<br>
<br>
<br>
<br>
The correct configuration example should look like this (for somedummy.crt/key certificate you can either use some self signed or just any other valid certificate (since nginx checks the validity of ssl certificates at startup/config reload you can't place nonexisting/nonvalid certs here)):<br>
<br>
<br>
<br>
server {<br>
listen 443;<br>
ssl_certificate somedummy.crt;<br>
ssl_certificate_key somedummy.key;<br>
server_name _;<br>
return 444;<br>
}<br>
<br>
server {<br>
listen 443 ssl;<br>
ssl_certificate validdomain.crt;<br>
ssl_certificate_key validdomain.key;<br>
server_name validdomain;<br>
return 200 'Works';<br>
}<br>
<br>
<br>
Then the curl requests with Host injects should work as expected:<br>
<br>
curl --verbose <a href="https://validdomain" rel="noreferrer" target="_blank">https://validdomain</a><br>
<br>
> GET / HTTP/1.1<br>
> Host: validdomain<br>
><br>
< HTTP/1.1 200 OK<br>
* Connection #0 to host validdomain left intact<br>
Works<br>
<br>
<br>
curl --verbose --header 'Host: invalidhost' <a href="https://validdomain" rel="noreferrer" target="_blank">https://validdomain</a><br>
<br>
> GET / HTTP/1.1<br>
> Host: invalidhost<br>
><br>
* Empty reply from server<br>
* Connection #0 to host validdomain left intact<br>
curl: (52) Empty reply from server<br>
<br>
<br>
<br>
<br>
p.s. for further testing you should note also that curl doesn't use the Host header for SNI (<a href="https://github.com/curl/curl/issues/607" rel="noreferrer" target="_blank">https://github.com/curl/curl/issues/607</a> ) rather than the one in the url<br>
<br>
So something like:<br>
<br>
curl --verbose --header 'Host: validhostname' <a href="https://127.0.0.1" rel="noreferrer" target="_blank">https://127.0.0.1</a><br>
will fail with:<br>
curl: (51) SSL: no alternative certificate subject name matches target host name '127.0.0.1'<br>
<br>
<br>
will fail but on the other hand (if your somedummy.crt has an actual domain):<br>
<br>
curl --verbose --header 'Host: validdomain' <a href="https://somedummy" rel="noreferrer" target="_blank">https://somedummy</a><br>
<br>
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384<br>
> GET / HTTP/1.1<br>
> Host: validdomain<br>
<br>
< HTTP/1.1 200 OK<br>
< Server: nginx/1.17.8<br>
* Connection #0 to host somedummy left intact<br>
Works<br>
<br>
the dummy ssl certificate will be used but nginx will serve the validdoman virtualhost .<br>
<br>
rr<br>
<br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a></blockquote><div><br></div><div>Thanks Reinis for a detailed explanation. It worked as expected. Thanks a lot for all the help and much appreciated.</div></div></div>