首页 > 解决方案 > 将docker中的nginx conf映射到正确的位置

问题描述

我一直在努力对我的 docker app 进行更改。经过大量试验和错误后,我认为我的 nginx conf 文件实际上可能不是我的 nginx conf 文件。

我已经确定了这一点,因为我尝试完全删除它并且我的应用程序与 docker 运行相同。

看起来我通过 app.conf 文件对我的 nginx 服务所做的更改对我的应用程序的其余部分没有影响。

我试图了解我的卷映射是否正确。这是我的码头工人撰写:

version: "3.5"
services:
  collabora:
    image: collabora/code
    container_name: collabora
    restart: always
    cap_add:
      - MKNOD
    environment:
      - "extra_params=--o:ssl.enable=false --o:ssl.termination=true"
      - domain=mydomain\.com
      - dictionaries=en_US
    ports:
      - "9980:9980"
    volumes:
      - ./appdata/collabora:/config    
  nginx:
    image: nginx:1.15-alpine
    restart: unless-stopped
    depends_on:
      - certbot   
      - collabora 
    volumes:
#      - ./data/nginx:/etc/nginx/conf.d
      - ./data/nginx:/etc/nginx
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    ports:
      - "80:80"
      - "443:443"
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
  certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

我的项目目录是:

/我的项目

然后我的 app.conf 有各种 nginx 设置

server {
    listen 80;
    server_name example.com www.example.com;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}  ... more settings below

假设我的 app.conf 文件没有被使用是正确的,我怎样才能正确地将本地的 app.conf 映射到 nginx 容器中的正确位置?

标签: dockernginxdocker-compose

解决方案


nginx conf目录是

/etc/nginx/nginx.conf

此文件包含来自的所有内容

/etc/nginx/conf.d/*

您可以验证您的 nginx.conf 正在使用执行ps -ef | grep nginx在你的容器上。验证您的 default.conf。无论如何,在你的作文中你必须有:

volumes:
- ./data/nginx:/etc/nginx/conf.d

尝试使用绝对路径

问候


推荐阅读