繁体   English   中英

Nginx、Certbot & Docker 撰写:/etc/nginx/user.conf.d/*.conf:没有这样的文件或目录

[英]Nginx, Certbot & Docker Compose: /etc/nginx/user.conf.d/*.conf: No such file or directory

我正在使用 docker 和 Z05B6053C41A21430AFD6FC3B168 撰写的 Rails web 应用程序上运行 Ruby。 I had 3 containers functioning on the ip address at port 3000. I am now trying to set this up on the ip address/domain name rather than port 3000. To do this, I am trying to use nginx as a proxy server with this image ( https://hub.docker.com/r/staticfloat/nginx-certbot/ )这样我也可以拥有 SSL 证书。

我的问题是我仍然无法从没有端口 3000 的 ip 地址访问应用程序。此外,它只能通过 http 而不是 Z5E056C500A1C4B6A7110B50D807BADEZ5 访问。

当我运行“docker-compose up”时,我从 nginx 容器收到以下 output:

frontend_1       | templating scripts from /etc/nginx/user.conf.d to /etc/nginx/conf.d
frontend_1       | Substituting variables
frontend_1       |  -> /etc/nginx/user.conf.d/*.conf
frontend_1       | /scripts/util.sh: line 125: /etc/nginx/user.conf.d/*.conf: No such file or directory
frontend_1       | Done with startup
frontend_1       | Run certbot
frontend_1       | ++ parse_domains
frontend_1       | ++ for conf_file in /etc/nginx/conf.d/*.conf*
frontend_1       | ++ xargs echo
frontend_1       | ++ sed -n -r -e 's&^\s*ssl_certificate_key\s*\/etc/letsencrypt/live/(.*)/privkey.pem;\s*(#.*)?$&\1&p' /etc/nginx/conf.d/certbot.conf
frontend_1       | + auto_enable_configs
frontend_1       | + for conf_file in /etc/nginx/conf.d/*.conf*
frontend_1       | + keyfiles_exist /etc/nginx/conf.d/certbot.conf
frontend_1       | ++ parse_keyfiles /etc/nginx/conf.d/certbot.conf
frontend_1       | ++ sed -n -e 's&^\s*ssl_certificate_key\s*\(.*\);&\1&p' /etc/nginx/conf.d/certbot.conf
frontend_1       | + return 0
frontend_1       | + '[' conf = nokey ']'
frontend_1       | + set +x

我认为下面的 output 与我的问题有关。 但是,我仍然无法弄清楚这一点。

/scripts/util.sh: line 125: /etc/nginx/user.conf.d/*.conf: No such file or directory

我有两个.conf 文件,它们都位于 myapp/config/nginx/user.conf.d/

这是 two.conf 文件:

upstream docker {
    server web:3000 fail_timeout=0;
}

server {
    listen              443 ssl;
    server_name         myapp.com;
    ssl_certificate     /etc/letsencrypt/live/myapp.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;
    try_files $uri/index.html $uri @docker;
    client_max_body_size 4G;

    location @docker {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://docker;
    }
}

upstream docker {
    server web:3000 fail_timeout=0;
}

server {
    listen              443 ssl;
    server_name         myapp.ie;
    ssl_certificate     /etc/letsencrypt/live/myapp.ie/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myapp.ie/privkey.pem;
    try_files $uri/index.html $uri @docker;
    client_max_body_size 4G;

    location @docker {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://docker;
    }
}

这是我的 dockerfile:

# Use the Ruby 2.7.2 image from Docker Hub as the base image (https://hub.docker.com/_/ruby)
FROM ruby:2.7.2-buster

# The directory to store this application's files.
RUN mkdir /myapp
RUN mkdir -p /usr/local/nvm
WORKDIR /myapp

# Install 3rd party dependencies.
RUN apt-get update -qq && \
    apt-get install -y curl \
    build-essential \
    libpq-dev \
    postgresql \
    postgresql-contrib \
    postgresql-client

# # The directory to store this application's files.
# RUN mkdir /myapp
# RUN mkdir -p /usr/local/nvm
# WORKDIR /myapp

RUN curl -sL https://deb.nodesource.com/setup_15.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

# Copy Gems.
COPY Gemfile Gemfile.lock package.json yarn.lock ./

# Run bundle install to install the Ruby dependencies.
RUN gem install bundler && bundle update --bundler && bundle install
RUN npm install -g yarn && yarn install --check-files

# Copy all the application's files into the /myapp directory.
COPY . /myapp

# Compile assets
ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
RUN bundle exec rake assets:precompile

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process by setting "rails server -b 0.0.0.0" as the command to run when this container starts.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

这是我的 entrypoint.sh 文件:

#!/bin/bash
set -e

# For development check if the gems as installed, if not, then uninsstall them.
if ! [ bundle check ] ; then
    bundle install
fi

# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid

# # Yarn - Check Files.
yarn install --check-files

# Run the command - runs any arguments passed into this entrypoint file.
exec "$@"

这是我的 docker-compose.yml 文件:

version: "3.8"
services:
  web:
    restart: unless-stopped
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - bundle-volume:/usr/local/bundle
    ports:
      - "3000:3000"
    depends_on:
      - database
      - elasticsearch
    environment:
      RAILS_ENV: production
      DATABASE_NAME: myapp_production
      DATABASE_USER: postgres
      DATABASE_PASSWORD: **********
      POSTGRES_PASSWORD: **********
      DATABASE_HOST: database
      ELASTICSEARCH_URL: http://elasticsearch:9200

  database:
    restart: unless-stopped
    image: postgres:12.3
    container_name: database
    volumes:
      - db_volume:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - 5432:5432
    environment: 
      DATABASE_PASSWORD: **********
      POSTGRES_PASSWORD: **********

  elasticsearch:
    restart: unless-stopped
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    volumes:
      - ./docker_data/elasticsearch/data:/usr/share/elasticsearch/data
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    ports:
      - 9200:9200
    ulimits:
      memlock:
        soft: -1
        hard: -1

  frontend:
    restart: unless-stopped
    image: staticfloat/nginx-certbot
    ports:
        - 80:80/tcp
        - 443:443/tcp
    depends_on:
      - web
    environment:
        CERTBOT_EMAIL: myapp@gmail.com
    volumes:
      - /etc/nginx/user.conf.d:/etc/nginx/user.conf.d:ro
      - letsencrypt:/etc/letsencrypt

volumes:
  bundle-volume:
    external: false
  db_volume:
  data:
  letsencrypt:
    external: false

感谢任何帮助。

正如您提到的,您有两个.conf 文件,它们都位于 myapp/config/nginx/user.conf.d/ 中。

请将这两个文件移动到'/etc/nginx/user.conf.d',这个目录我可以看到你已经将此目录安装到docker。 将这些文件移动到上述位置后,关闭 docker 并打开,然后查看是否可以解决问题。 如果我能在这方面提供更多帮助,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM