gpt4 book ai didi

ruby-on-rails - 使用弹性 beanstalk 部署的 Rails 应用程序响应 "site can' t bereach"

转载 作者:行者123 更新时间:2023-12-03 21:31:39 24 4
gpt4 key购买 nike

我使用以下堆栈构建了一个 rails 应用程序:

  • Puma(应用服务器)3.0
  • Ruby on Rails 5.0
  • 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"

    我什至尝试更改根路径的 Controller 以呈现简单的 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:

    我在我 friend 的笔记本电脑上打开了这个网址。它打开了。似乎问题出在我的系统代理上。现在我可以删除我的系统代理,但我不能确定访问我网站的用户。有没有办法将弹性 beantalk 与系统代理一起使用?同时,我会在互联网上爱抚同样的。

    编辑 3:
    我尝试在笔记本电脑中从 safari 打开网站。有用。但它不适用于 Google Chrome。

    编辑 4:
    我从浏览器中清除了缓存,并且成功了!一个教训。

    最佳答案

    将 Rails 应用程序部署到弹性 beantalk 后,我收到 504 网关超时错误。在应用程序的根目录中添加一个名为“Procfile”(无扩展名)的文件,内容为

    web: bundle exec puma -C /opt/elasticbeanstalk/config/private/pumaconf.rb
    解决了我的问题。

    关于ruby-on-rails - 使用弹性 beanstalk 部署的 Rails 应用程序响应 "site can' t bereach",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41704667/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com