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

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

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

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

nginx

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

Ruby on Rails

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

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

Q&A

解決済

1回答

929閲覧

Nginxで不明なエラー。(capistrano + nginx + unicorn)

sakanafuto

総合スコア0

unicorn

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

nginx

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

Ruby on Rails

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

Capistrano

Rubyで書かれたサーバオーケストレーションで、複数のサーバでスクリプトを実行する際に用いられます。主な使用用途はWebアプリケーションのデプロイメントです。 アプリケーションのバージョンアップ自動化、およびデータベースの変更などもできます。

0グッド

0クリップ

投稿2020/07/06 07:32

編集2020/07/07 03:59

前提・実現したいこと

先日完成したRailsアプリケーションをデプロイしようとしたところNginxでエラーが起こってしまいました。対処法を調べても見つからなかったので質問させていただきます。

Nginx + Unicorn + Capistranoを利用した自動デプロイの途中です。

bundle exec cap production deployをすると、偶に DEBUG [18a39419] Finished in 0.614 seconds with exit status 1 (failed).のようにfailedと言われる部分もありましたが途中でエラーで中断されることもなく最後まで進みました。

いざIPアドレスにアクセスしてみるとWe're sorry, but something went wrong.の文字、、、。

$ ps auxwww | grep unicornでunicorn masterをkillして再デプロイしても変わらず、mysqlを見てみても

$ sudo service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ]

異常はなし。

発生している問題・エラーメッセージ

nginxの様子を確かめてみると

[Stelle@ip-x-x-x-x ~]$ nginx -t nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2020/07/06 06:51:02 [warn] 12762#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5 2020/07/06 06:51:02 [emerg] 12762#0: "client_max_body_size" directive is duplicate in /etc/nginx/conf.d/stelle2.conf:5 nginx: configuration file /etc/nginx/nginx.conf test failed

と言われたので$ sudo cat /var/log/nginx/error.logをしてみると

2020/07/06 04:42:57 [emerg] 12186#0: "client_max_body_size" directive is duplicate in /etc/nginx/conf.d/stelle2.conf:5

といわれ、/etc/nginx/conf.dからsudo rm stelle2.confをしてもう一度$ sudo cat /var/log/nginx/error.logしても同じく

2020/07/06 04:42:57 [emerg] 12186#0: "client_max_body_size" directive is duplicate in /etc/nginx/conf.d/stelle2.conf:5

と言われるだけでした。。。

該当ファイル

/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 /var/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; index index.html index.htm; server { listen 80 default_server; listen [::]:80 default_server; 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 http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # 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 { # } # } }

本命である/etc/nginx/conf.d/Stelle.confです

error_log /var/www/rails/stelle/current/log/nginx.error.log; access_log /var/www/rails/stelle/current/log/nginx.access.log; client_max_body_size 2G; upstream app_server { server unix:/var/www/rails/stelle/current/tmp/sockets/.unicorn.sock fail_timeout=0; } server { listen 80; server_name 3.xxx.xxx.xx; keepalive_timeout 5; root /var/www/rails/stelle/current/public; 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 /var/www/rails/stelle/current/public; } }

config.ruです

# This file is used by Rack-based servers to start the application. require_relative 'config/environment' run Rails.application

エラーの意味だけでも教えていただけたら幸いです。。。

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

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

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

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

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

yukky1201

2020/07/06 08:10

stelle2.confは本当に削除されていますか?(rmコマンド実行後に確認しましたか) もし、残っていればファイルの設定内容を質問に追記してください
sakanafuto

2020/07/06 08:37

確認してみたところ削除されていました。 もう一度~から$ nginx -tをしてみると nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2020/07/06 08:30:02 [warn] 742#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2020/07/06 08:30:02 [emerg] 742#0: open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed となりました。 /etc/nginx/conf.d/Stelle.confも追加しました。
yukky1201

2020/07/06 09:10

# nginx -t (rootで実行) または $ sudo nginx -t (root権限で実行) するとどうなりますか
sakanafuto

2020/07/06 09:21

[Stelle@x.xxx.xxx.xx ~]$ nginx -t nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2020/07/06 09:17:19 [warn] 871#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2020/07/06 09:17:19 [emerg] 871#0: open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed [Stelle@x.xxx.xxx.xx ~]$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [emerg] open() "/var/www/rails/stelle/current/log/nginx.error.log" failed (2: No such file or directory) nginx: configuration file /etc/nginx/nginx.conf test failed 違いが出ました。 エラーログについてもう少し見てみます。
yukky1201

2020/07/07 01:31

"/var/www/rails/stelle/current/log/nginx.error.log" failed (2: No such file or directory) に関しては、手動でファイルを作成しておくか、該当ディレクトリがnginxユーザの書き込み権限があるか確認してください。
sakanafuto

2020/07/07 02:10

(local)と(server)とでパスが違っていたことがわかり、(local)の 「app_path = '/var/www/stelle'」の通り(server)側の「/etc/nginx/conf.d/Stelle.conf」内の/var/www/rails/stelleの記述を全て/var/www/stelleに修正しました。 その結果 [Stelle@xxx stelle]$ nginx -t nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2020/07/07 01:58:24 [warn] 29752#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2020/07/07 01:58:24 [emerg] 29752#0: open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed とPermission deniedとなってしまいました。nginxを再起動させてもダメでした。 /etc/nginx/nginx.conf:5ですから「user nginx;」に問題があるのでしょうか。。。
yukky1201

2020/07/07 02:59

nginx -tは管理者権限で実行してください
sakanafuto

2020/07/07 03:58

[Stelle@x.x.x.x stelle]$ sudo nginx -t [sudo] password for Stelle: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful こちらでは成功していました。 他も確かめるために、 [Stelle@x.x.x.x stelle]$ cd /var/www/stelle/current/log をして$ tail unicorn.rbをすると /var/www/stelle/shared/bundle/ruby/2.6.0/gems/rack-2.2.3/lib/rack/builder.rb:125:in `initialize' config.ru:1:in `new' config.ru:1:in `<main>' /var/www/stelle/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.5/lib/unicorn.rb:54:in `eval' /var/www/stelle/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.5/lib/unicorn.rb:54:in `block in builder' /var/www/stelle/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:795:in `build_app!' /var/www/stelle/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.5/lib/unicorn/http_server.rb:141:in `start' /var/www/stelle/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.5/bin/unicorn:128:in `<top (required)>' /var/www/stelle/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `load' /var/www/stelle/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `<top (required)>' というログが出てきました。。。 config.ruは一切弄っていません。
sakanafuto

2020/07/07 05:21

更にエラーログを見てみるとArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_keyが見つかりました。こちらはネットに情報がたくさんあるのでがんばります。
guest

回答1

0

自己解決

ユーザーから作り直すことにしました。

投稿2020/07/07 13:51

sakanafuto

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問