1. 在容器内创建一个nginx配置文件,比如/etc/nginx/conf.d/default.conf,内容如下: server { listen 80; server_name example.com; root /var/www/example.com; index index.html; } 2. 将该文件复制到宿主机上,比如/etc/nginx/conf.d/default.conf 3. 在docker-compose.yml文件中添加一个volume,指向宿主机上的nginx配置文件: volumes: - /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf 4. 重启容器,使配置生效: docker-compose restart