How to force Apache Bench to use the IP addresses specified in / etc / hosts?

I am using ApacheBench for load testing. I would like ab to resolve the host name using the IP address specified in / etc / hosts on my Mac. How can I make it? curl has the --resolve option to do just that, as stated here . I am looking for something similar for ab.

+4
source share
2 answers

Think of it differently: you can say that Curl hit the IP address, and specify a title Hostto start the domain you need.

curl example.com
curl --header "Host: example.com" 93.184.216.34

The same method works abusing a flag -Has such

ab -n 10 -c 10 http://example.com/
ab -n 10 -c 10 -H "Host: example.com" http://93.184.216.34/

Hope this helps.

Edit:

Piggybacking @Magistar, , (http vs https) FQD. , www.example.com, example.com ( www), , .

- , . , ab yahoo.com ( ) , yahoo.com www.yahoo.com, , curl :

# curl yahoo.com
redirect
# curl yahoo.com -v
* About to connect() to yahoo.com port 80 (#0)
*   Trying 98.139.180.180...
* Connected to yahoo.com (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: yahoo.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:46:53 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp29.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host yahoo.com left intact
redirect

, , IP- :

# curl --header "Host: yahoo.com" 98.139.180.180 -v
* About to connect() to 98.139.180.180 port 80 (#0)
*   Trying 98.139.180.180...
* Connected to 98.139.180.180 (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Accept: */*
> Host: yahoo.com
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:51:26 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp82.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host 98.139.180.180 left intact
redirect

, curl url, , , ab.

+6

SSL 0 :

ab -n 10 -c 10 -H "Host: www.example.com" https://93.184.216.34/

, (www) .

(ps , ).

+1

Source: https://habr.com/ru/post/1570733/


All Articles