簡體   English   中英

使用彈性 beantalk 部署的 Rails 應用程序響應“站點無法訪問”

[英]Rails app deployed using elastic beanstalk responds with “site can't be reached”

我使用以下堆棧構建了一個 rails 應用程序:

  1. Puma(應用服務器)3.0
  2. Ruby on Rails 5.0
  3. PostgreSQL 9.5.3

我嘗試將此應用程序部署到 aws elastic beanstalk 並成功做到了。 但是,當我嘗試訪問 beanstalk 生成的網址時,應用服務器上沒有命中。 幾分鍾后,瀏覽器會拋出“無法訪問站點”。

以下是必要的日志:

美洲獅日志

=== puma startup: 2017-01-17 18:10:06 +0000 ===
=== puma startup: 2017-01-17 18:10:06 +0000 ===
[1501] - Worker 0 (pid: 1504) booted, phase: 0

/var/log/nginx/error.log

2017/01/17 18:03:08 [warn] 703#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/01/17 18:25:00 [warn] 2043#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/01/17 18:25:00 [warn] 2050#0: conflicting server name "localhost" on 0.0.0.0:80, ignored

/var/app/containerfiles/logs/production.log

D, [2017-01-17T18:10:02.564332 #1397] DEBUG -- :    (1.0ms)  SELECT pg_try_advisory_lock(6778635641374256100);
D, [2017-01-17T18:10:02.574041 #1397] DEBUG -- :   ActiveRecord::SchemaMigration Load (1.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2017-01-17T18:10:02.591019 #1397] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.7ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2  [["key", :environment], ["LIMIT", 1]]
D, [2017-01-17T18:10:02.596200 #1397] DEBUG -- :    (1.0ms)  BEGIN
D, [2017-01-17T18:10:02.598152 #1397] DEBUG -- :    (1.0ms)  COMMIT
D, [2017-01-17T18:10:02.599249 #1397] DEBUG -- :    (0.9ms)  SELECT pg_advisory_unlock(6778635641374256100)

盡管多次重新加載,此 production.log 仍保持原樣。 我在任何日志中都沒有發現任何錯誤。

進一步參考:

這是我的其他幾個文件:

配置/美洲獅.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/
  # deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

文件

source 'https://rubygems.org'

# Ruby gem
 ruby '2.3.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Gemfile for password hashing
gem 'bcrypt', '3.1.11'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'jquery-ui-rails', '~> 5.0', '>= 5.0.5'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'select2-rails'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Upload files
gem 'carrierwave', '>= 1.0.0.rc', '< 2.0'
# Image resizing
gem 'mini_magick', '~> 4.5', '>= 4.5.1'
# Image upload in production
gem 'fog-aws'
# Autoprefix CSS
gem "autoprefixer-rails"
# Google Maps API
gem 'geocoder'
# Redis
gem 'redis', '~> 3.3', '>= 3.3.1'
# For postgres full text search
gem 'pg_search'
# Font awesome support
gem "font-awesome-rails"
# Google oauth-2
gem "omniauth-google-oauth2"
# Facebook omniauth
gem 'omniauth-facebook'

group :production do
  gem 'remote_syslog_logger'
end

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'better_errors', '~> 2.1', '>= 2.1.1'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'rails_layout'
  gem 'seed_dump', '~> 3.2', '>= 3.2.4'
  gem 'rubocop', '~> 0.44.1', require: false
  gem 'binding_of_caller', '~> 0.7.2'
  gem 'meta_request'
  gem 'rack-mini-profiler', '~> 0.10.1'
  gem 'brakeman', :require => false
  gem 'bullet'
end

group :test do
  gem 'rails-controller-testing', '0.1.1'
  gem 'minitest-reporters',       '1.1.9'
  gem 'guard',                    '2.13.0'
  gem 'guard-minitest',           '2.4.4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

除此之外,在我對 google 和 stackoverflow 的個人研究之后,我嘗試了一些東西:

我將以下內容附加到我的 puma 配置文件( puma.rb )中:

bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"

我什至嘗試更改根路徑的控制器以呈現簡單的 hello,而不是嘗試從數據庫中獲取數據。 但主要問題似乎是請求沒有到達應用程序,從production.log 中的零日志條目可以看出這一點。

我還嘗試刪除Gemfile 中提供的 puma 版本號,希望更新版本可以解決此問題。

我還嘗試多次重新啟動 nginx 服務器和應用程序服務器。 但似乎沒有什么能夠拋出一個有意義的錯誤。

為了確保這不是數據庫問題,我通過 ssh 連接到 eb cli,並使用了 rails 控制台。 控制台工作得很好。 所以,這不是數據庫問題。

如果有人能幫助我,我真的很感激,至少讓我在日志中出現一個有意義的錯誤。

編輯 1:正如 Sahil 所問,nginx.conf 文件是:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.fedora.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen       80 ;
        listen       [::]:80 ;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
            location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl;
#        listen       [::]:443 ssl;
#        server_name  localhost;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        # It is *strongly* recommended to generate unique DH parameters
#        # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
#        #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#        ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }


}

除此之外,在我的 production.rb 文件中:

config.force_ssl = true

編輯2:

我在我朋友的筆記本電腦上打開了這個網址。 它打開了。 似乎問題出在我的系統代理上。 現在我可以刪除我的系統代理,但我不能確定訪問我網站的用戶。 有沒有辦法將彈性 beantalk 與系統代理一起使用? 同時,我會在互聯網上愛撫同樣的。

編輯 3:我嘗試在筆記本電腦中從 safari 打開網站。 有用。 但它不適用於 Google Chrome。

編輯 4:我從瀏覽器中清除了緩存,並且成功了! 一個教訓。

將 Rails 應用程序部署到彈性 beantalk 后,我收到 504 網關超時錯誤。 在應用程序的根目錄中添加一個名為“Procfile”(無擴展名)的文件,內容為

web: bundle exec puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb

解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM