headers-more-nginx-module
nginx에서 특정 헤더에 값을 수정할 수 있는 모듈이다.
nginx에 포함되지 않은 third-party 모듈로 별도 설치가 필요하다.
도커로 nginx를 사용할 때 외부 모듈을 사용하려면, 모듈이 설치된 도커 이미지를 만들어야 한다.
고맙게도 nginx 공식 repo에서 작성해 둔 Dockerfile이 있다.
https://github.com/nginxinc/docker-nginx/tree/master/modules
docker-nginx/modules at master · nginxinc/docker-nginx
Official NGINX Dockerfiles. Contribute to nginxinc/docker-nginx development by creating an account on GitHub.
github.com
$ docker build --build-arg ENABLED_MODULES="headers-more" -t my-nginx-with-headers-more .
(자세한 내용은 repo README 참고)
Dockerfile을 복사하거나 다운받고, pkg-oss repository에서 설치 가능한 외부 모듈을 인자로 설정하여 빌드
+) 도커 이미지를 빌드할 때, 서버 인스턴스에서 돌리면 메모리 부족으로 에러가 나올 수 있다.
리소스가 넉넉한 환경에서 빌드하고 registry에 push/pull로 사용하는 것이 좋다.
nginx 설정
# nginx.conf
load_module modules/ngx_http_headers_more_filter_module.so;
...
http {
...
}
load_module을 잊지말고
location /server1 {
include common/_cors-header.conf;
include common/_cors-options-response.conf;
proxy_pass http://server1:9999;
proxy_set_header Host $http_host;
proxy_set_header Origin http://$http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
more_set_headers 'Set-Cookie: $sent_http_set_cookie; Path=/; Secure; SameSite=None';
}
리버스 프록시 역할을 하는 nginx의 경우, 서버 응답의 Set-Cookie 값을 수정하는 등, 헤더 value를 수정할 수 있다.
참고
https://stackoverflow.com/questions/72806335/add-more-set-headers-to-docker-image
Add more_set_headers to Docker image
I am trying to add a module to the base nginx container so I can set some headers. I am using the alpine image so i don't believe i can use apt-get. This is what I have tried: FROM nginx:stable-alp...
stackoverflow.com
'DevOps > Nginx' 카테고리의 다른 글
nginx reverse proxy로 CORS 해결하기 (0) | 2024.12.03 |
---|---|
docker-compose nginx load-balancing (spring, node, ws) (0) | 2023.08.28 |