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

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

这是我如何将http的所有curl或命令行请求重定向到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似乎完全可以正常工作。

您遇到的问题是,除非您通过添加-L--location命令行选项明确告知HTTP重定向,否则curl不支持HTTP重定向。

关于redirect - 当通过命令行使用curl时,HAproxy不会将请求从http转发到https,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37287183/

10-11 19:16
查看更多