【问题标题】:Dockerising Rails application: Error - "unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1" while running "docker-compose up"Dockerising Rails 应用程序:错误 - 运行“docker-compose up”时 /etc/nginx/conf.d/00_app_env.conf:1 中出现“意外的“d”
【发布时间】:2018-08-31 09:41:05
【问题描述】:

我正在使用nginxpassengerruby 2.4.0rails 5.1.6 对接我的rails 应用程序。

我正在关注 this 在 docker 上设置 phusion/passenger。

当我运行docker-compose up。它抛出以下错误:

nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1

这是完整的跟踪。

postgres_1      | 2018-08-31 09:26:31.495 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1      | 2018-08-31 09:26:31.495 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1      | 2018-08-31 09:26:31.502 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1      | 2018-08-31 09:26:31.526 UTC [47] LOG:  database system was shut down at 2018-08-31 09:26:31 UTC
postgres_1      | 2018-08-31 09:26:31.531 UTC [1] LOG:  database system is ready to accept connections
company_data_1  | *** Running /etc/my_init.d/30_presetup_nginx.sh...
company_data_1  | Aug 31 09:26:31 caeb10c704df syslog-ng[11]: EOF on control channel, closing connection;
company_data_1  | *** Running /etc/rc.local...
company_data_1  | *** Booting runit daemon...
company_data_1  | *** Runit started as PID 18
company_data_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 25) 0s
company_data_1  | Aug 31 09:26:31 caeb10c704df cron[23]: (CRON) INFO (pidfile fd = 3)
company_data_1  | Aug 31 09:26:31 caeb10c704df cron[23]: (CRON) INFO (Running @reboot jobs)
company_data_1  | nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 30) 0s
company_data_1  | nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 30) 0s
company_data_1  | nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 28#28: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 31#31: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 28#28: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 31#31: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 36) 0s
company_data_1  | nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 36) 0s
company_data_1  | nginx: [emerg] unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 28#28: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 31#31: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:36 [emerg] 34#34: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:36 [emerg] 37#37: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:32 [emerg] 24#24: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 28#28: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:34 [emerg] 31#31: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:36 [emerg] 34#34: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1
company_data_1  | 2018/08/31 09:26:36 [emerg] 37#37: unexpected "d" in /etc/nginx/conf.d/00_app_env.conf:1

Dockerfile

FROM ubuntu:16.04
FROM phusion/passenger-ruby24

LABEL Name=company_data Version=0.0.1
EXPOSE 80

RUN rm -f /etc/service/nginx/down
# ADD default /etc/nginx/sites-enabled/default
RUN rm /etc/nginx/sites-enabled/default
ADD company_financials.conf /etc/nginx/sites-enabled/company_financials.conf
ADD 00_app_env.conf /etc/nginx/conf.d/00_app_env.conf
ADD passenger.conf /etc/nginx/passenger.conf

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
RUN apt-get install -y nginx openssh-server git-core openssh-client curl
RUN apt-get install -y build-essential

WORKDIR /home/app/company_financials
COPY . /home/app/company_financials

RUN chmod -R 777 /home/app/company_financials

# install RVM, Ruby, and Bundler
RUN \curl -sSL https://get.rvm.io | bash
RUN /bin/bash -l -c "rvm install ruby 2.4.0"
RUN /bin/bash -lc 'rvm --default use ruby-2.4.0'
RUN /bin/bash -l -c "which ruby"
RUN /bin/bash -l -c "ls /usr/local/rvm/rubies/"
RUN /bin/bash -l -c "ls /home/app/company_financials"
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
RUN /bin/bash -l -c "bundle install"

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

docker-compose.yml

version: '2.1'

services:
  company_data:
    image: company_data
    build: .
    ports:
      - "80:80"
    env_file:
      - .env
    links:
      - postgres
      - redis
      - sidekiq
  redis:
    image: redis
    command: ["redis-server", "--appendonly", "yes"]
    hostname: redis
    restart: always
  postgres:
    image: 'postgres:10.3-alpine'
  sidekiq:
    build: .
    command: bundle exec sidekiq
    depends_on:
      - postgres
      - redis

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Phusion Passenger config
        ##
        # Uncomment it if you installed passenger or passenger-enterprise
        ##

        include /etc/nginx/passenger.conf;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/rvm/rubies/ruby-2.4.0/bin/ruby;

nginx_server.conf

server {
  listen 80;
  server_name "~^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" localhost;
  passenger_enabled on;
  passenger_user app;
  root /home/app/company_financials/public;
}

00_app_env.conf

passenger_app_env development;

【问题讨论】:

    标签: ruby-on-rails docker nginx


    【解决方案1】:

    根据:https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_app_env

    passenger_app_env 的上下文应该是 http, server, location, if。我从你的问题中看到的是 00_app_env.conf 没有嵌套在任何上下文中。

    您需要将此配置放在上下文中。

    例如。您的 passenger.conf 文件位于 http 上下文中,因为您将其 include /etc/nginx/passenger.conf; 包含在 http 上下文中。您需要对 00_app_env.conf 执行相同操作。

    【讨论】:

    • 在nginx配置中nginx.conf。我已经包含了这个include /etc/nginx/conf.d/*.conf;。这应该会处理/etc/nginx/conf.d/ 中的所有.conf 文件。但我还是试过了,还是不行。
    • 你是对的,我没有注意到这一点。你能尝试双引号开发吗?是"development" 而不是development?您是否尝试将passenger_app_env development; 直接放在nginx.conf 中?
    • 不,我没有尝试过。我会做的,会通知你的。
    • 我试过把passenger_app_env开发;直接在 nginx.conf 中,但发生了同样的错误。
    猜你喜欢
    • 2019-11-26
    • 1970-01-01
    • 2022-08-16
    • 2021-06-13
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2020-09-24
    相关资源
    最近更新 更多