AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1115189
Accepted
uberrebu
uberrebu
Asked: 2022-11-09 20:19:59 +0800 CST2022-11-09 20:19:59 +0800 CST 2022-11-09 20:19:59 +0800 CST

Nginx http 到 http redirect 400 纯 HTTP 请求被发送到 HTTPS 端口

  • 772

http://app1.internal.example.com:8080我有一个在端口上的 http 和端口上的 https 上公开的应用程序https://app1.internal.example.com:8443

所以我有 80 和 443 nginx 服务器块来帮助将来自 http 端口的请求重定向到应用程序的 https 端口

$ curl http://app1.internal.example.com:8080

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
</body>
</html>

$ curl -IL http://app1.internal.example.com:8080

HTTP/1.1 400 Bad Request
Date: Wed, 09 Nov 2022 00:39:30 GMT
Content-Type: text/html
Content-Length: 220
Connection: close

这是返回 200 的 https 端口上的 curl

$ curl -IL https://app1.internal.example.com:8443

HTTP/1.1 200 OK
Date: Wed, 09 Nov 2022 00:38:00 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 1274335
Connection: keep-alive
Keep-Alive: timeout=20
Vary: Accept-Encoding

下面是我的 nginx 服务器块,用于 http 到 https 重定向

我该如何修复此错误,以便 curl 可以在 http 请求上返回 200

server {
    listen 80;
    listen [::]:80;

    server_name app1.internal.example.com;

    return 301 https://app1.internal.example.com:8443$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name app1.internal.example.com;

    location ^~ / {
        proxy_pass http://localhost:5000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}
nginx
  • 1 1 个回答
  • 48 Views

1 个回答

  • Voted
  1. Best Answer
    uberrebu
    2022-11-10T00:13:34+08:002022-11-10T00:13:34+08:00

    问题已解决,碰巧有另一个配置文件在 ssl 上侦听端口 80,这导致了错误

    server {
        listen 80 ssl;
        listen [::]:80 ssl;
    
        server_name another-app1.internal.example.com;
    
        return 301 https://another-app1.internal.example.com:8443$request_uri;
    }
    
    server {
        listen 443 ssl;
        listen [::]:443 ssl;
    
        server_name another-app1.internal.example.com;
    
        location ^~ / {
            proxy_pass http://localhost:5000;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
        }
    }
    

    所以我只需要从端口 80 中删除 ssl,现在一切似乎都工作正常

    所以这里是没有 ssl 的 http 块应该是什么,一些较旧的 nginx 可能是ssl on;,你必须从端口 80 或 http 端口删除它。检查整个配置文件以确保没有遗漏任何一个,你应该没问题

    server {
        listen 80;
        listen [::]:80;
    
        server_name another-app1.internal.example.com;
    
        return 301 https://another-app1.internal.example.com:8443$request_uri;
    }
    
    ...
    ...
    
    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve