nginx.conf 파일에서 $header_<name>을 사용하면 된다.
custom header가 제대로 나오고 있는지 확인하기 위해
custom header 값으로 로그를 찍는 테스트를 진행해 봤다.
python 테스트 코드
import requests
def getAuthHeader():
# http 호출 헤더값 설정
http_header = {
'test': 'test-header',
'key': 'test-key',
}
return http_header
#header 생성
http_header = getAuthHeader()
#nginx가 있는 서버 ip 입력
response = requests.get('http://serverip', headers=http_header)
print (response)
nginx config
log_format main '"$http_test" "$http_key"';
프로그램 실행 후 nginx 로그를 확인하면
test-header, test-key라는 로그가 남는 걸 확인할 수 있다.
해당 header로 특정 서비스 차단이나 허용도 가능하니
자신의 환경에 맞게 쓰면 좋을 것 같다.
'Nginx' 카테고리의 다른 글
nginx log 경로 변경 후 오류 (13: Permission denied) while logging request (0) | 2023.07.11 |
---|---|
Nginx 오류 a duplicate default server for 0.0.0.0:80 (0) | 2023.07.10 |
Nginx restrict access by ip 사용자 ip로 제한하기-2(추가작업) (0) | 2023.06.27 |
Nginx restrict access by ip 사용자 ip로 제한하기 (0) | 2023.06.26 |
Nginx resolver 설정(Dynamic DNS resolution) (0) | 2023.06.12 |