Кабель действия не работает на развертывании с докером - PullRequest
0 голосов
/ 10 января 2019

У меня проблема с моим приложением Ruby on rails 5. В Developpement все работает, но когда я развертываю с помощью Docker на моем сервере (Ubuntu 16 LTS), кабель действия не работает.

Я следовал за этими туфлями:

Вот мои файлы:

  • докер-compose.yml

    
    version: '3'
    services:
      db:
        image: postgres:9.6
        environment:
          - ACIM_DATABASE_PASSWORD=ACIM_2018
        volumes:
          - 'db:/var/lib/postgresql/data'
        env_file:
          - '.env'
        expose:
          - '5432'
        ports:
          - "7000:5432"
      nginx: 
        image: nginx:latest
        container_name: production_nginx
        volumes:
          - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
          - public-content:/var/www/acim/public
        ports:
          - 80:80
          - 443:443
        links:
        - web
    
      # maildev:
      #   image: djfarrelly/maildev
      #   ports:
      #     - "2000:80"
    
      redis:
        image: redis
        command: redis-server
        volumes:
          - 'redis:/data'
        ports:
          - "6379"
    
      sidekiq:
        build: .
        #command: sidekiq -C config/sidekiq.yml
        command: bundle exec sidekiq
        volumes:
          - .:/ACIM
        links:
          - db
          - redis
        depends_on:
          - db
          - redis
        env_file:
          - '.env'
      web:
        build: .
        command: bundle exec rails s -p 3000 -b '0.0.0.0'
        volumes:
          - bundle_cache:/bundle
          - public-content:/var/www/acim/public
          - .:/ACIM
        ports:
          - "5000:3000"
        depends_on:
          - db
          - redis
        env_file:
          - '.env'
    
      cable:
        depends_on:
          - 'redis'
        build: .
        command: puma -p 28080 cable/config.ru
        ports:
          - '28080:28080'
        volumes:
          - '.:/ACIM'
        env_file:
          - '.env'
    
    volumes:
      bundle_cache:
      redis:
      db:
      public-content:
    
  • Мой Dockerfile

    FROM ruby:2.5.1
    
    # Install dependencies
    RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
    
    ENV RAILS_ROOT /var/www/acim/public
    RUN mkdir -p $RAILS_ROOT
    RUN mkdir -p $RAILS_ROOT/log
    RUN rm -rf /var/www/acim/public/tmp/pids/server.pid
    
    # Set working directory, where the commands will be ran:
    WORKDIR $RAILS_ROOT
    
    # Setting env up
    ENV RAILS_ENV='production'
    ENV RACK_ENV='production'
    
    # Adding gems
    COPY Gemfile Gemfile
    COPY Gemfile.lock Gemfile.lock
    RUN bundle install --jobs 20 --retry 5 --without development test
    
    # Adding project files
    COPY . .
    RUN bundle exec rake assets:precompile
    
    EXPOSE 3000
    CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
    
    • Мой файл NGINX

    user www-data;
    worker_processes 4;
    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;
    
        ##
        # Logging Settings
        ##
    
        # access_log /var/log/nginx/access.log;
        # error_log /var/log/nginx/error.log;
    
        upstream acim {
            server 192.168.99.100:5000;
        }
    
        server {
        listen 0.0.0.0;
        server_name 192.168.99.100;
    
        root /var/www/acim/publc;
    
        # define where Nginx should write its logs
        # access_log /var/www/acim/log/nginx.access.log;
        # error_log /var/www/acim/log/nginx.error.log;
    
        try_files $uri/index.html $uri @app;
    
        location / {
            proxy_pass http://acim;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
        }
    
        location /assets/ {
            expires 1y;
            add_header Cache-Control public;
            add_header ETag "";
            root /var/www/acim/public/public;
        }
    
        location /cable {
            proxy_pass http://192.168.99.100:28080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }
        location /redis {
            proxy_pass http://192.168.99.100:6379;
        }
    
        error_page 500 502 503 504 /500.html;
        client_max_body_size 4G;
        keepalive_timeout 10;
      }
    }
    
    
  • Мой конфиг / environements / production.rb

    Rails.application.configure do
      # Settings specified here will take precedence over those in config/application.rb.
    
      # Code is not reloaded between requests.
      config.cache_classes = true
    
      # Eager load code on boot. This eager loads most of Rails and
      # your application in memory, allowing both threaded web servers
      # and those relying on copy on write to perform better.
      # Rake tasks automatically ignore this option for performance.
      config.eager_load = true
    
      # Full error reports are disabled and caching is turned on.
      config.consider_all_requests_local       = true
      config.action_controller.perform_caching = true
    
      # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
      # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
      # config.require_master_key = true
    
      # Disable serving static files from the `/public` folder by default since
      # Apache or NGINX already handles this.
      config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
    
      # Compress JavaScripts and CSS.
      config.assets.js_compressor = :uglifier
      # config.assets.css_compressor = :sass
    
      # Do not fallback to assets pipeline if a precompiled asset is missed.
      config.assets.compile = false
    
      # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
    
      # Enable serving of images, stylesheets, and JavaScripts from an asset server.
      # config.action_controller.asset_host = 'http://assets.example.com'
    
      # Specifies the header that your server uses for sending files.
      # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
       config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
    
    
      # Store uploaded files on the local file system (see config/storage.yml for options)
      config.active_storage.service = :local
    
      # Mount Action Cable outside main process or domain
      # config.action_cable.mount_path = nil
      config.action_cable.url = 'ws://192.168.99.100/cable'
      config.action_cable.allowed_request_origins = [ 'http://192.168.99.100', /http:\/\/192.168.99.100.*/ ]
    
      #config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
      #config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
    
      # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
      # config.force_ssl = true
    
      # Use the lowest log level to ensure availability of diagnostic information
      # when problems arise.
      config.log_level = :debug
    
      # Prepend all log lines with the following tags.
      config.log_tags = [ :request_id ]
    
      # Use a different cache store in production.
      # config.cache_store = :mem_cache_store
    
      # Use a real queuing backend for Active Job (and separate queues per environment)
      # config.active_job.queue_adapter     = :resque
      # config.active_job.queue_name_prefix = "ACIM_#{Rails.env}"
    
      config.action_mailer.perform_caching = false
    
      # Ignore bad email addresses and do not raise email delivery errors.
      # Set this to true and configure the email server for immediate delivery to raise delivery errors.
      # config.action_mailer.raise_delivery_errors = false
    
      # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
      # the I18n.default_locale when a translation cannot be found).
      config.i18n.fallbacks = true
    
      # Send deprecation notices to registered listeners.
      config.active_support.deprecation = :notify
    
      # Use default logging formatter so that PID and timestamp are not suppressed.
      config.log_formatter = ::Logger::Formatter.new
    
      # Use a different logger for distributed setups.
      # require 'syslog/logger'
      # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
    
      if ENV["RAILS_LOG_TO_STDOUT"].present?
        logger           = ActiveSupport::Logger.new(STDOUT)
        logger.formatter = config.log_formatter
        config.logger    = ActiveSupport::TaggedLogging.new(logger)
      end
    
      # Do not dump schema after migrations.
      config.active_record.dump_schema_after_migration = false
    
    
      # ne pas directement servir les fichiers public 
      # en utilisant ruby, mais passons par NGINX
      config.public_file_server.enabled = false
      config.assets.js_compressor = Uglifier.new(harmony: true)
    end
    
    Rails.application.config.assets.precompile += %w( *.js ^[^_]*.css *.css.erb )
    

Вот выходные данные сети вкладок [WS] инструментов chrome developper. Chrome Developper Tool-> Сеть -> WS

Не могли бы вы мне помочь? Спасибо

...