nginx 에서 header 명칭에 _ 를 사용하면 헤더가 누락되는 경우가 발생한다.
이는 cgi 변수와 맵핑할 때 충돌?을 방지하기 위한 거라는데
실제로 아래와 같이 php 를 이용하여 테스트 해보면
헤더에 underscore 가 없는 상태.
[root@abc /var/www/html/]# curl -H 'test: test' --insecure https://localhost/test.php
Array
(
[USER] => nginx
[HOME] => /var/lib/nginx
[FCGI_ROLE] => RESPONDER
[PATH_INFO] =>
[PATH_TRANSLATED] => /var/www/html/test.php
[SCRIPT_FILENAME] => /var/www/html/test.php
[QUERY_STRING] =>
[REQUEST_METHOD] => GET
[CONTENT_TYPE] =>
[CONTENT_LENGTH] =>
[SCRIPT_NAME] => /tt.php
[REQUEST_URI] => /tt.php
[DOCUMENT_URI] => /tt.php
[DOCUMENT_ROOT] => /var/www/html/chu
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_SCHEME] => https
[HTTPS] => on
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_SOFTWARE] => nginx/1.16.1
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 60237
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 443
[SERVER_NAME] => abc
[SERVER_NAME] => 111
[REDIRECT_STATUS] => 200
[HTTP_USER_AGENT] => curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
[HTTP_HOST] => localhost
[HTTP_ACCEPT] => /
[PHP_SELF] => /test.php
[REQUEST_TIME] => 1587547665
)
헤더에 undersocre 를 추가하고 다시 시도를 해보면
[root@abc /var/www/html/]# curl -H 'test_test: test' --insecure https://localhost/test.php
Array
(
[USER] => nginx
[HOME] => /var/lib/nginx
[FCGI_ROLE] => RESPONDER
[PATH_INFO] =>
[PATH_TRANSLATED] => /var/www/html/test.php
[SCRIPT_FILENAME] => /var/www/html/test.php
[QUERY_STRING] =>
[REQUEST_METHOD] => GET
[CONTENT_TYPE] =>
[CONTENT_LENGTH] =>
[SCRIPT_NAME] => /tt.php
[REQUEST_URI] => /tt.php
[DOCUMENT_URI] => /tt.php
[DOCUMENT_ROOT] => /var/www/html/chu
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_SCHEME] => https
[HTTPS] => on
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_SOFTWARE] => nginx/1.16.1
[REMOTE_ADDR] => 127.0.0.1
[REMOTE_PORT] => 60256
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 443
[SERVER_NAME] => abc
[REDIRECT_STATUS] => 200
[HTTP_USER_AGENT] => curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
[HTTP_HOST] => localhost
[HTTP_ACCEPT] => /
[PHP_SELF] => /test.php
[REQUEST_TIME] => 1587547786
)
이는 아래 옵션을 server or http 구문에 추가하여 수신할 수 있다.
underscores_in_headers on;
옵션을 추가하고 해보면...
[root@abc /app/nginx/sbin]# curl -H 'test_test: test' --insecure https://localhost/test.php 2>&1 | grep -i test_test
참고 사이트 :
https://stackoverflow.com/questions/3136253/how-to-print-all-information-from-an-http-request-to-the-screen-in-php
http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers
https://stackoverflow.com/questions/22856136/why-do-http-servers-forbid-underscores-in-http-header-names
https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/