Nginx,Certbot和Docker撰写:/etc/nginx/user.conf.d / *。conf:没有此类文件或目录

约翰·汉隆

我正在使用docker和docker compose运行Ruby on Rails Web应用程序。我有3个容器在端口3000的IP地址上运行。我现在尝试在IP地址/域名而不是端口3000上进行设置。为此,我尝试将nginx用作此映像的代理服务器(https://hub.docker.com/r/staticfloat/nginx-certbot/),以便我也可以拥有SSL证书。

我的问题是,没有端口3000我仍然无法从IP地址访问应用程序。而且,只能使用http而不是https进行访问。

当我运行docker-compose up时,我从nginx容器收到以下输出:

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

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

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

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

这是两个.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 arguements passed into this entrypoint file.
exec "$@"

这是我的docker-compose.yml ile:

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: [email protected]
    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

感谢任何帮助。

帕万·亚达夫(Pavan Yadav)

如您所述,您有两个.conf文件,它们都位于myapp / config / nginx / user.conf.d /。

请将这两个文件都移动到“ /etc/nginx/user.conf.d”目录下,因为我看到您已经将该目录挂载到了docker。将这些文件移动到上述位置后,请关闭泊坞窗并打开,然后查看它是否可以解决问题。请让我知道是否可以提供更多帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Postgres,Go Docker编写wait-for-it.sh没有此类文件或目录

Docker:构建映像时出现“ lstat没有此类文件或目录”错误。文件在那里

在Tensorflow Docker映像上启动convolutional.py脚本时,“没有此类文件或目录”

Dockerfile中的Docker构建显示“ ADD失败-没有此类文件或目录”

具有Docker文件支持的Visual Studio-没有此类文件或目录

makefile错误:打开依赖文件.d / file_name.Td:没有此类文件或目录

Docker远程上的Pycharm远程解释器:[Errno 2]没有此类文件或目录

退出代码127和':没有此类文件或目录`

Jenkins代理无法运行程序“ docker”:error = 2,没有此类文件或目录

Docker Compose:无法运行ssh:没有此类文件或目录

Docker无法复制Nginx conf

Docker容器打印“没有此类文件或目录”

无法在nginix /etc/nginx/conf.d/default.conf中复制配置文件

docker-compose构建失败,没有此类文件或目录

/ bin / sh:设置docker-compose入口点时没有此类文件或目录

运行Docker映像时没有此类文件或目录错误

全新安装的恢复模式网络-resolve.conf:没有此类文件或目录

无法为ios和android添加平台(错误:ENOENT,没有此类文件或目录)

Nginx说open()“ /etc/nginx/conf.d/foo.conf”失败(13:权限被拒绝)

无法在docker中运行脚本文件,没有此类文件或目录

xorg.conf.d文件有编号约定吗?

PHP-FPM:nginx / error.log中的“没有此类文件或目录”错误。路径或权限问题?

lstate错误:使用Docker build命令从自定义映像构建Docker时,没有此类文件或目录

httpd中的conf、conf.d和conf.modules.d目录有什么区别?

nginx.conf 没有正确重启

为什么“RUN rm /etc/nginx/conf.d/default.conf”没有成功?

致命:解析“conf/gitolite.conf-compiled.pm”失败:没有这样的文件或目录

使用 Docker 和 NGINX 编辑 nginx.conf 的问题

python 有没有办法通过从 conf 文件中读取源目录和目标目录来移动 Windows 上的文件?