nginx - Nginx Docker的容器:使用自定义index.html设置默认主页

标签 nginx docker home-directory

我使用docker容器,并为nginx构建了一个。

我将用index.html更改nginx的主页。

我怎样才能告诉我的Nginx容器在哪里找到我的自定义index.html并用我的索引替换他自己的index.html?

最佳答案

您只需在Dockerfile中放入 COPY command ADD command,即可将index.html文件复制到NGiNX提供的文件(由root指令定义,例如/data/www/index.html)

COPY <src>... <dest>
ADD <src>... <dest>

这里:
COPY /path/to/your/index.html /data/www/index.html
ADD /path/to/your/index.html /data/www/index.html

注意,RUNCOPY优于ADD:

The first encountered ADD instruction will invalidate the cache for all following instructions from the Dockerfile if the contents of <src> have changed.
This includes invalidating the cache for RUN instructions.



这就是suggestion made in the comments更好的原因:

if you have few changes


RUN sed -i -e"s/aaa/bbb" /data/www/index.html 

如果您进行了许多更改,ADD仍然是有效的选项(首先尝试COPY),但是请尝试将其放在dockerfile的末尾,而不是开头或中间。

关于nginx - Nginx Docker的容器:使用自定义index.html设置默认主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29535153/

相关文章:

nginx conf 文件 : Detect if browser language is "de", 然后重定向到页面 ....否则重定向到其他页面

http - 如何更改 HTTP 响应 header 中的服务器名称?

debugging - 如何调试 Docker?

Linux VSFTPD : Jail a "Specific User" to its home?

nginx - Nginx 和 php-fpm 中的随机 "No input files specified"

在 Systemd 中使用 Gunicorn 套接字的 Centos 7 上的 Nginx 权限问题

docker - 使用 ELK 堆栈的最佳 Docker 日志记录架构

mysql - 配置 Apache 503 敏感度

java - 如何使用 Gradle 应用程序插件传递对分发主目录的引用?

Linux:卸载程序后删除应用程序设置?