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;
}
}
uj5u.com熱心網友回復:
問題已解決,碰巧有另一個組態檔在 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;
}
...
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/536958.html
上一篇:如何重定向具有代碼的Url
