nginx 无法正确响应 HTTP/1.1

nginx 无法正确响应 HTTP/1.1

我遇到了一个问题,某些客户端首先尝试通过 HTTP/1.1 进行连接,但无法正确转发到 HTTPS

curl -v http://indentationerror.com/
*   Trying 217.45.175.173:80...
* Connected to indentationerror.com (217.45.175.173) port 80 (#0)
> GET / HTTP/1.1
> Host: indentationerror.com
> User-Agent: curl/7.73.0
> Accept: */*
> 
* Received HTTP/0.9 when not allowed

* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed

但是,使用以下命令:

curl -v http://indentationerror.com/ --http2-prior-knowledge

nginx 按预期通过 HTTP/2 返回 301 重定向

我的配置目前是:

server {
        server_name www.indentationerror.com;
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        ssl    on;
        root "/http/indentationerror.com/www";
        include /etc/nginx/genericHandlers/indentationerror.com;
}

server {
        server_name indentationerror.com;
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;
        ssl    on;
        root "/http/indentationerror.com/www";
        include /etc/nginx/genericHandlers/indentationerror.com;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name $host;
        return 301 https://$host$request_uri;   
}

损坏的部分(发现问题后添加):

server {
    server_name api.indentationerror.com;
    listen 80 http2;
    listen [::]:80 http2;
    root "/http/indentationerror.com/api";

    include /etc/nginx/genericHandlers/indentationerror.com;
}

server {
    server_name api.indentationerror.com;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    ssl    on;
    root "/http/indentationerror.com/api";
    include /etc/nginx/genericHandlers/indentationerror.com;

}

答案1

我的一个 80 端口服务器指令中意外出现了“http2”指令(您可以在“api”服务器中看到它)。出于某种原因,在一个服务器块上使用此指令会影响其他服务器块。感谢 Michael 的提示。对于遇到此问题的其他任何人,请从全部端口 80 服务器解决了该问题。

相关内容