Nginx downloads empty file when requested on port 80 (instead of redirecting to port 443)

301-redirectdomain-name-systemhttp-headershttpsnginx

my nginx webserver does not do, what he should. All http:// requests to the server should be redirected with http 301 to https://, it worked fine for the last few days, until it stopped working without any changes.

Nginx returns an empty file with type "application/octet-stream" and following content (readable in sublime):

0000 1204 0000 0000 0000 0300 0000 8000
0400 0000 0000 0500 ffff ff00 0004 0800
0000 0000 7fff 0000 0000 0807 0000 0000
0000 0000 0000 0000 01

First I tried to remove the line

default_type application/octet-stream;

from my nginx.conf, but it did not help.

The http-response header returns

Status: �����

My server block for the 301 redirect from http:// to https:// looks as follows

server {
   listen 80;
   listen [::]:80;
   server_name my.tld www.my.tld;
   return 301 https://$server_name$request_uri;
}

Nginx does not log anything, when it receives a http:// request. (/var/log/nginx/error.log | /var/log/nginx.access.log). Also PHP7.0-fpm.

Everything required is installed, updated & upgraded. A restart of the services and of the server itself did not help.

Here is the output from curl -v http://my.tld/

* Connected to my.tld (123.123.123.123) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: my.tld
> Accept: */*
> 
< HTTP/1.1 200 OK
< Mime-Version: 1.0
< Date: Thu, 06 Oct 2016 06:10:53 GMT
< X-Transformed-From: HTTP/0.9
< Transfer-Encoding: chunked
< Connection: keep-alive
< 
* Connection #0 to host my.tld left intact

Why nginx returns a 200 OK when it should return 301 permanent redirect?

I have not changed anything, it worked with the same configs …I hope someone can help me :-(. Could it possibly be a DNS problem?

Best,
Unkn0wn0x

Best Answer

I've solved the problem. It was a config file from a subdomain which had a own root-directory configured. The config file from the subdomain had

listen 80 http2;
listen [::]:80 http2

which affected the whole webserver without any errors / log files or similar (nginx -t also positive). After I reinstalled nginx and backed up the config files step by step, I found the error.

Thanks for the support.

Best, Unkn0wn0x