cURL --resolve

user-pic
Vote 0 Votes

curl 要測試自訂的域名及綁定 IP 通常是在 hosts 設定
curl 在 7.21.3 之後, 加了一個 --resolve 參數, 可以在本身綁定而不需修改 hosts

例:
curl --resolve domain.com:80:192.168.1.1 http://domain.com
curl --resolve domain.com:443:192.168.1.1 https://domain.com
它就會直接去連 192.168.1.1 而不會參考域名的解析

PHP 在 5.5.0 之後 curl_setopt 也加入 CURLOPT_RESOLVE 參數
$ch = curl_init("https://domain.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RESOLVE, array("domain.com:443:192.168.1.1"));
echo curl_exec($ch);

CentOS 6 的 curl 版本是 7.19.7, 不支援, 需升級 libcurl 及 curl
rpm -ivh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-2-1.rhel6.noarch.rpm
yum-config-manager --enable city-fan.org
yum -y update curl

CentOS 7 的 curl 版本是 7.29.0, 已有支援 --resolve, 但若想裝最新版的 curl, 還是可以裝 city-fan.org repo
rpm -ivh http://www.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/city-fan.org-release-2-1.rhel7.noarch.rpm
yum-config-manager --enable city-fan.org
yum -y update curl

About this Entry

This page contains a single entry by Pank published on August 21, 2019 5:46 PM.

Caddy Web Server was the previous entry in this blog.

Chocolatey is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives