質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Q&A

0回答

384閲覧

Nginx + rails + unicorn環境で、railsルーティングで指定したindex.htmlが表示されない

退会済みユーザー

退会済みユーザー

総合スコア0

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

0グッド

0クリップ

投稿2020/04/11 11:55

自作アプリをAWSのEC2でデプロイしようとしています。
EC2インスタンスには独自ドメイン(www.example.com) を割り当てています。
http://www.example.comにアクセスすると、このページは動作していませんとエラーが出ます。
http://www.example.com/index.htmlにアクセスすると、Welcome to nginx on Amazon Linux!のページが表示され、また/var/www/projects/rails_app/publicに適当にindex.htmlを作成すると、そのページがhttp://www.example.comに表示されます。
rails_app/app/view/static_pages/index.htmlをルートに表示するにはどのように設定すればいいのでしょうか。

console

1$ curl -I -L http://www.example.com 2HTTP/1.1 301 Moved Permanently 3Server: awselb/2.0 4Date: Sat, 11 Apr 2020 11:32:03 GMT 5Content-Type: text/html 6Content-Length: 150 7Connection: keep-alive 8Location: https://www.example.com:443/ 9 10HTTP/2 204 11date: Sat, 11 Apr 2020 11:32:03 GMT 12server: nginx/1.16.1 13x-frame-options: SAMEORIGIN 14x-xss-protection: 1; mode=block 15x-content-type-options: nosniff 16x-download-options: noopen 17x-permitted-cross-domain-policies: none 18referrer-policy: strict-origin-when-cross-origin 19cache-control: no-cache 20x-request-id: 46232335-ee08-4e5a-8371-d5cef433a33c 21x-runtime: 0.001718 22strict-transport-security: max-age=31536000; includeSubDomains

以下/etc/nginx/conf.d/rails_app.conf

#log directory error_log /var/www/projects/rails_app/log/nginx.error.log; access_log /var/www/projects/rails_app/nginx.access.log; #max body size client_max_body_size 2G; upstream app_server { # for UNIX domain socket setups server unix:/var/www/projects/rails_app/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name www.example.com; # nginx so increasing this is generally safe... keepalive_timeout 5; # path for static files root /var/www/projects/rails_app/public; # page cache loading 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_no_cache true; proxy_pass http://app_server; } # Rails error pages error_page 500 502 503 504 /500.html; location = /500.html { root /var/www/projects/rails_app/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/doc/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 { } }

以下unicornの設定ファイル

# set lets $worker = 2 $timeout = 30 $app_dir = "/var/www/projects/rails_app" $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 # set config worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid # loading booster preload_app true # 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

表示したいページのルーティング
routes.rb

Rails.application.routes.draw do root to: 'static_pages#home' end

#その他の環境
ドメインはroute53で取得、AWS Certificate Managerで証明書発行済
ロードバランサーALBを設定中

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問