首页 > 解决方案 > Dockerising Rails 应用程序:错误 - 运行“docker-compose up”时 /etc/nginx/conf.d/00_app_env.conf:1 中出现“意外的“d”

问题描述

我正在使用 、 和 dockerising 我的nginxrailspassenger应用ruby 2.4.0程序rails 5.1.6

我正在按照这个在 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/*

码头工人-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_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-railsdockernginx

解决方案


根据: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.


推荐阅读