使用 docker 容器时,请求标头是网络设置的
Dockerfile
FROM nginx:1.23.3-alpine
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
nginx.conf
events{}
http {
map "$http_abc" $abc{}
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
add_header Set-Cookie "abc=$abc; Path=/;";
}
}
}
Docker 构建/运行
docker build -f ./Dockerfile . -t abc
docker run -d -p 8888:80 --name competent_swirles abc
进行测试的curl命令
curl localhost:8888 -H "abc:123" --verbose