HTTP 1.1 스펙에 따르면 반드시 Host 헤더를 추가해야 한다고 한다.


https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html


14.23 Host

The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (generally an HTTP URL,

as described in section 3.2.2). The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL. This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root "/" URL of a server for multiple host names on a single IP address.

       Host = "Host" ":" host [ ":" port ] ; Section 3.2.2

A "host" without any trailing port information implies the default port for the service requested (e.g., "80" for an HTTP URL). For example, a request on the origin server for <http://www.w3.org/pub/WWW/> would properly include:

       GET /pub/WWW/ HTTP/1.1
       Host: www.w3.org

A client MUST include a Host header field in all HTTP/1.1 request messages . If the requested URI does not include an Internet host name for the service being requested, then the Host header field MUST be given with an empty value. An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field.


간단히 테스트 해본다.



// $ curl -v -I -o /dev/null  http://.....jpg  아래 커맨드와 동일하다. 알아서 host 헤더를 채운다.

$ curl -v -I -o /dev/null -H "host:plus.google.com" http://.....jpg

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 1.1.1.1

* Connected to ...

> HEAD ....jpg HTTP/1.1

> host:plus.google.com

> User-Agent: curl/7.43.0

> Accept: */*

>

< HTTP/1.1 200 OK

< Server: openresty

< Date: Wed, 01 Feb 2017 08:41:06 GMT

< Content-Type: image/jpg

< Content-Length: 23357

< Connection: keep-alive

< X-Kakao-crc32: 75299291

< Expires: Thu, 31 Dec 2037 23:55:55 GMT

< Cache-Control: max-age=315360000

< Age: 601526

<

  0 23357    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

* Connection #0 to host plus.google.com left intact


하지만 host가 없으면 400 에러가 뜬다.


$ curl -v -I -o /dev/null -H "host:" http://.....jpg

* Connected to ...

> HEAD ....jpg HTTP/1.1

> host:

> User-Agent: curl/7.43.0

> Accept: */*

>

< HTTP/1.1 400 Bad Request





따라서 reverse proxy 설정할 때 종종 빠뜨릴 수 있는데. 


HTTP 1.1 서비스를 위해 proxy_set_header을 추가해야 한다. (이것 땜시 삽질해서 정리해둠)


proxy_set_header Host $host;



Posted by '김용환'
,


git clone할 때, yes/no 질문을 물어보지 않도록 설정할 수 있다. 



$ git clone http://github.com/afasdfas

Are you sure you want to continue connecting (yes/no)?


 ~/.ssh/config에 다음 내용을 추가한다. ansible이나 capistano에서 적절히 스크립트로 만든다.


Host github.com

     StrictHostKeyChecking no



그리고 다시 git clone하면 잘 동작한다.


$ git clone http://github.com/afasdfas

....




Posted by '김용환'
,




reverse proxy 기능을 사용하기 위해 location 블럭을 정규식으로 작성하고 proxy_pass를 사용할 때 no resolver defined to resolve 가 발생할 수 있다. 



location ~ "^/(case|meta)/(.*)$" {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host plus.google.com;
proxy_pass http://dn.google.com/image/$2${args};
}


2017/02/01 20:00:21 [error] 61700#0: *103 no resolver defined to resolve dn.google.com,



다음처럼 resolver 지시자에 사내 DNS를 추가하면 해당 이슈가 발생하지 않는다.



location ~ "^/(case|meta)/(.*)$" { resolver 1.2.3.4;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host plus.google.com;
proxy_pass http://dn.google.com/image/$2${args};
}








Posted by '김용환'
,