通过命令行使用 curl 时,HAproxy 不会将请求从 http 转发到 https

HAproxy is not forwarding request from http to https while using curl through command line

我已经配置 HAProxy.This 将通过浏览器将特定域从 http 重定向到 https。它通过浏览器满足了我的所有要求。

但是当我尝试通过 curl(命令行)使用 api 时,它在我使用 http:// 时不起作用

我的疑问是如何将所有 curl 或命令行请求从 http 重定向到 https。这是我尝试使用 http curl 时的输出。

$ curl -s -v  -u $USER:$PASS -X GET -H "Content-Type: application/json" http://<IP>/rest/api/2/project/
*   Trying 192.168.1.21...
* Connected to test-jira.example.com (192.168.1.21) port 80 (#0)
* Server auth using Basic with user 'prash.castlestreet'
GET /rest/api/2/project/ HTTP/1.1
Host: prash.castlestreet.example.com
Authorization: Basic cHJhZGVlcC5jaGVydXRodWRpeWlsZ2lyaWphdmFsbGFiaGFuOlZlcml6b24h
User-Agent: curl/7.43.0
Accept: */*
Content-Type: application/json

HTTP/1.1 302 Found
Cache-Control: no-cache
Content-length: 0
Location: https://prash.castlestreet.example.com/rest/api/2/project/
Connection: close

Closing connection 0

谢谢, 普拉斯

HAProxy 似乎在正常工作。

您遇到的问题是 curl 不接受 HTTP 重定向,除非您通过添加 -L--location 命令行选项明确告诉它这样做。