Score:0

Nginx http to http redirect 400 The plain HTTP request was sent to HTTPS port

bv flag

i have an app that is exposed at http on port http://app1.internal.example.com:8080 and https on port https://app1.internal.example.com:8443

so i have the 80 and 443 nginx server block to help redirect request coming on the http port to the https port of the app

$ 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

and here is curl on the https port which returns 200

$ 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

below is my nginx server block for the http to https redirect

how do i fix this error so curl can return 200 on the http request

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;
    }
}
in flag
`The plain HTTP request was sent to HTTPS port` sounds to me like your assumption that 8080 is HTTP is wrong. Both ports are configured to server HTTPS.
in flag
And TBH, I don't see the relation between this nginx config and your curl requests. There is nothing matching here.
Score:1
bv flag

Issue fixed, happened that there was another config file that had port 80 listening on ssl which was causing the error

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;
    }
}

so i just had to remove the ssl from the port 80 and all seems to work fine now

so here is what that http block should be without the ssl, some older nginx may be ssl on;, you have to remove that from port 80 or the http port. Check the whole config files to make sure there is not one missed and you should be fine

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

    server_name another-app1.internal.example.com;

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

...
...
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.