1

概述


我在 myRailsApp 上使用 AWS(EC2)+Nginx+Uniconr 制作生产环境。我完成了与 EC2 和 Nginx 设置、独角兽设置的连接。但我不能开始独角兽。

我试过独角兽版本下来(5.5.1→5.4.1)

我是初学者,我尝试了三天。但我不知道。你能帮我么?


独角兽版本 5.4.1

#myapp/config/unicorn.conf.rb

worker_processes 3
timeout 1200
listen File.expand_path 'tmp/sockets/.unicorn.sock', '/var/www/rails/myapp'
pid    File.expand_path 'tmp/pids/unicorn.pid', '/var/www/rails/myapp'
stderr_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log')
stdout_path File.expand_path('unicorn.log', File.dirname(__FILE__) + '/../log')
preload_app true
working_directory '/var/www/rails/myapp'

# before starting processes
 before_fork do |server, worker|
   defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
   old_pid = "#{server.config[:pid]}.oldbin"
   if old_pid != server.pid
     begin
       Process.kill "QUIT", File.read(old_pid).to_i
     rescue Errno::ENOENT, Errno::ESRCH
     end
   end
 end
 # after finishing processes
 after_fork do |server, worker|
   defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
 end
#cd /etc/nginx/nginx.conf

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

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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;

    upstream unicorn {
        server unix:/var/www/rails/myapp/tmp/sockets/unicorn.sock;
    }

    server {
        listen       80;
        server_name  IP;
        root         /var/www/rails/myapp/public;
        try_files    $uri/index.html $uri @unicorn;
        proxy_buffer_size 32k;
        proxy_buffers 50 32k;
        proxy_busy_buffers_size 32k;

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

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /500.html {
             root /var/www/rails/myapp/public;
        }

        location @unicorn {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

$ unicorn_rails -c /var/www/rails/myapp/config/unicorn.conf.rb -D -E 生产日志

I, [2019-11-16T14:15:45.889685 #14254]  INFO -- : Refreshing Gem list
/home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:244:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:268:in `handle_settings'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/service.rb:98:in `new'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/fog-core-2.1.2/lib/fog/core/services_mixin.rb:16:in `new'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/carrierwave-2.0.2/lib/carrierwave/storage/fog.rb:68:in `eager_load'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/carrierwave-2.0.2/lib/carrierwave.rb:77:in `block in <class:Railtie>'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/application/finisher.rb:118:in `block in <module:Finisher>'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `instance_exec'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:32:in `run'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/initializable.rb:60:in `run_initializers'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.1/lib/rails/application.rb:363:in `initialize!'
    from /var/www/rails/appname/config/environment.rb:5:in `<top (required)>'
    from config.ru:4:in `require_relative'
    from config.ru:4:in `block in <main>'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
    from config.ru:1:in `new'
    from config.ru:1:in `<main>'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `eval'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn.rb:56:in `block in builder'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:139:in `block in rails_builder'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:795:in `build_app!'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:139:in `start'
    from /home/myname/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn_rails:209:in `<top (required)>'
    from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `load'
    from /home/myname/.rbenv/versions/2.6.3/bin/unicorn_rails:23:in `<main>'

systemctl 状态 nginx

$ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since 土 2019-11-16 11:20:28 UTC; 2h 50min ago
Process: 2479 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 2476 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 2475 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 2482 (nginx)
CGroup: /system.slice/nginx.service
├─2482 nginx: master process /usr/sbin/nginx
└─8241 nginx: worker process
4

0 回答 0