Set cURL to use local virtual hosts

后端 未结 7 1647
囚心锁ツ
囚心锁ツ 2020-11-28 01:37

Using Apache or Ngnix I always create development sites based on real projects such as http://project1.loc which, after adding to my .hosts file, t

7条回答
  •  失恋的感觉
    2020-11-28 01:57

    EDIT: While this is currently accepted answer, readers might find this other answer by user John Hart more adapted to their needs. It uses an option which, according to user Ken, was introduced in version 7.21.3 (which was released in December 2010, i.e. after this initial answer).


    In your edited question, you're using the URL as the host name, whereas it needs to be the host name only.

    Try:

    curl -H 'Host: project1.loc' http://127.0.0.1/something
    

    where project1.loc is just the host name and 127.0.0.1 is the target IP address.

    (If you're using curl from a library and not on the command line, make sure you don't put http:// in the Host header.)

提交回复
热议问题