大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 …

问题原文

原帖链接 · Unkn0wn0x · CC BY-SA 3.0

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

社区高分解答

原帖链接 · Unkn0wn0x · CC BY-SA 3.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-10-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。