railsアプリを、capistranoを使ってaws ec2にデプロイしました。
webサーバはnginx, appサーバはunicornを使っています。
しかし、ipアドレスに curl 【ipアドレス】
などでアクセスしても、レスポンスが返って来ません。
/home/tomohiroo/pecopeco/shared/log/nginx.error.log
と /home/tomohiroo/pecopeco/shared/log/unicorn.log
には、なにも表示されず、
(userはtomohiroo, appnameはpecopecoです。)
pecopeco/shared/log/nginx.access.log
に
xxx.xxx.xxx.xxx(クライアントのipアドレス) - - [15/Sep/2018:18:52:13 +0900] "GET / HTTP/1.1" 301 5 "-" "curl/7.54.0"
と, 301エラーのログが書いてあります。。
どうすれば、アクセスできるのでしょうか?
関係あるのかがよくわかっていないのですが、
➜ ~ echo -en 'GET / HTTP/1.0\r\n\r\n' | socat stdio /home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock
を叩くと
HTTP/1.1 301 Moved Permanently Date: Sun, 16 Sep 2018 10:14:09 GMT Connection: close Content-Type: text/html Location: https://localhost/ Vary: Origin
と出て来ます。
/etc/nginx/conf.d/pecopeco.confは以下です
error_log /home/tomohiroo/pecopeco/current/log/nginx.error.log; access_log /home/tomohiroo/pecopeco/current/log/nginx.access.log; client_max_body_size 2G; upstream app_server { server unix:/home/tomohiroo/pecopeco/current/tmp/sockets/unicorn.sock fail_timeout=0; } server { listen 80; server_name xx.xxx.xxx.xxx; keepalive_timeout 5; root /home/tomohiroo/pecopeco/current/public; # try_files $uri/index.html $uri.html $uri @app; location / { try_files $uri/index.html $uri.html $uri @app; } location @app { # HTTP headers proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_server; } error_page 500 502 503 504 /500.html; location = /500.html { root /home/tomohiroo/pecopeco/current/public; } }
/etc/nginx/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 /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; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # 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 { } }
以下ローカルのファイルです。
config/unicorn/production.rb
$worker = 2 $timeout = 30 $app_dir = "/home/tomohiroo/pecopeco/current" $listen = File.expand_path 'tmp/sockets/unicorn.sock', $app_dir $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir $std_log = File.expand_path 'log/unicorn.log', $app_dir worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid preload_app true 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_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
config/Capfile
require 'capistrano/setup' require 'capistrano/deploy' require 'capistrano/rbenv' require 'capistrano/bundler' require 'capistrano/rails/migrations' require 'capistrano/console' Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } require "capistrano/scm/git" install_plugin Capistrano::SCM::Git
config/deploy.rb
# config valid for current version and patch releases of Capistrano lock "~> 3.11.0" set :application, "pecopeco" set :repo_url, "git@github.com:nakamotoo/pecopeco.git" set :branch, 'master' set :deploy_to, '/home/tomohiroo/pecopeco' set :linked_files, %w{config/master.key config/secrets.yml} set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} set :keep_releases, 5 set :rbenv_ruby, '2.5.1' set :log_level, :debug set :repo_tree, 'server' set :default_env, { JAVA_HOME: "/usr/java/jdk1.8.0_181-amd64" } namespace :deploy do desc 'Restart application' task :restart do invoke 'unicorn:restart' end desc 'Create database' task :db_create do on roles(:db) do |host| with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:create' end end end end desc 'Run seed' task :seed do on roles(:app) do with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:seed_fu' end end end end after :publishing, :restart after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do end end end
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/15 02:58 編集
2018/09/15 02:58
2018/09/15 03:06 編集
2018/09/15 03:14
2018/09/15 04:06
2018/09/15 04:15
2018/09/15 04:38
2018/09/15 08:49 編集
2018/09/15 04:47
2018/09/15 04:48
2018/09/15 04:53
2018/09/15 04:58
2018/09/15 05:00
2018/09/15 08:48
2018/09/15 09:00 編集
2018/09/15 09:11 編集
2018/09/15 09:19
2018/09/15 09:50
2018/09/15 11:11 編集