docker - 在 docker 上更改 Cache-Control nginx 容器
问题描述
我在我的 linux 上安装了 docker,并像这样安装了 nginx 容器:
docker pull nginx
docker run -it -d -p 8081:80 --name web -v /mnt/Project/Flutter/Projects/app_web2/build/web:/usr/share/nginx/html nginx
现在我想改变Cache-Control
我的 nginx 容器。因为我用flutter写了一个pwa,每次我改变我的页面,当我启动页面时,我仍然看到旧版本的页面,现在我想改变nginx缓存。如何更改它的默认值?
解决方案
我怀疑你可以直接实现这一点。有两种方法。
现在运行 nginx 容器。然后执行以下操作。
docker exec -it <<containername>>
转到 /etc/nginx/conf.d/default.conf (编辑此文件)
注意:这种方法是有问题的,因为您每次都必须这样做。
另一种方法是基于 nginx 创建自定义图像。
FROM nginx:latest COPY ./default.conf /etc/nginx/conf.d/default.conf
这个 ./default.conf 将驻留在您的目录中,并从您执行以下命令的位置。
docker build . mynginx:latest
在您的目录中的这个 default.conf 中,您可以添加自定义标头。
您可以在这里找到示例:https ://github.com/jp1482/mynginxwithcustomerheader