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

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

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

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

Ruby on Rails 6

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

HTTPS

HTTPS(Hypertext Transfer Protocol Secure)はHypertext Transfer プロトコルとSSL/TLS プロトコルを組み合わせたものです。WebサーバとWebブラウザの間の通信を暗号化させて、通信経路上での盗聴や第三者によるなりすましを防止します。

nginx

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

SSL

SSL(Secure Sockets Layer)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

Q&A

解決済

1回答

2491閲覧

nginxでSSL証明書が反映されない

taba.3011

総合スコア12

unicorn

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

Ruby on Rails 6

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

HTTPS

HTTPS(Hypertext Transfer Protocol Secure)はHypertext Transfer プロトコルとSSL/TLS プロトコルを組み合わせたものです。WebサーバとWebブラウザの間の通信を暗号化させて、通信経路上での盗聴や第三者によるなりすましを防止します。

nginx

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

SSL

SSL(Secure Sockets Layer)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

0グッド

0クリップ

投稿2021/03/03 16:20

前提・実現したいこと

nginxとunicornを使用しています。
SSL証明書を取得してnginxのconfigファイルに反映させる記述をしたのですが、うまく読み込めていない状態です。
nginx自体は起動でき、ブラウザも正常に起動しているのですがhttps通信になりません。

nginx -tコマンド実行時

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2021/03/03 15:16:13 [warn] 11059#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 2021/03/03 15:16:13 [emerg] 11059#0: open() "/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed

しかし、sudo nginx -tコマンドだと、successfulな結果になります。

/etc/nginx/nginx.conf.default

upstream app_server { server unix:/var/www/stock-info/tmp/sockets/unicorn.sock; } #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # server { listen 443 ssl; server_name stockapp.work; ssl_certificate /etc/nginx/ssl/stock.crt; ssl_certificate_key /etc/nginx/ssl/stock.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } } }

/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 4096; 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; listen [::]:80; server_name _; root /usr/share/nginx/html; # 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 = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2; # listen [::]:443 ssl http2; # server_name stockapp.work; # root /usr/share/nginx/html; # # ssl_certificate /etc/nginx/ssl/stock.csr; # ssl_certificate_key /etc/nginx/ssl/stock.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers PROFILE=SYSTEM; # ssl_prefer_server_ciphers on; # # 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 = /50x.html { # } # } }

/etc/nginx/nginx.d/rails.conf

upstream app_server { server unix:/var/www/stock-info/tmp/sockets/unicorn.sock; } server { listen 80; server_name 35.73.34.193; client_max_body_size 2g; root /var/www/stock-info/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { 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; }

試したこと

SSL設定マニュアル通りに実行しましたがうまくいかず、他のサイトを参考にconfファイルをいじりましたがなかなか解決しません。
SSLを実装するにあたって編集したのは/etc/nginx/nginx.conf.defaultファイルの最下部 HTTPS serverの部分のみです。ただ、 HTTPS serverの部分をコメントアウトしても挙動は変わらないので、そもそも参照されてないのだと思います。

nginx.confやngonx.conf.defaultやnginx/conf.dなど設定ファイルがいくつもあるのですが、まだこの辺の理解が曖昧なためどこの設定を編集すればいいのかがわかりません。それ故、情報が足りない部分もあるかと存じますのでその際は追記依頼をしていただけると幸いです。どなたかSSL証明書に詳しい方がいらっしゃいましたら、教えていただきたいです。よろしくお願いします。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。
Rails 6.0.3.5
nginx/1.18.0
unicorn v5.8.0

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

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

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

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

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

hoshi-takanori

2021/03/03 19:29

OS の種類とバージョンを教えてください。また、動作環境は?
taba.3011

2021/03/04 00:01

hoshi-takanori様コメントありがとうございます! ・macOS Big Sur バージョン11.2.1 デプロイ先はAWSのec2を使用しています ・Amazon Linux 2 AMI (HVM), SSD Volume Type ・t2.micro データベース ・MariaDb すみません動作環境について今まで考えたことがなかったのですが、上記の情報で大丈夫でしょうか?
hoshi-takanori

2021/03/04 05:53

OS の種類とバージョンは、SSL 証明書を反映したい nginx が動いてるやつ (ec2 ですよね?) のことです。 また、「https通信になりません」というのはどうやって確認しましたか?
taba.3011

2021/03/04 07:39

システムログから確認したところ、 OS:Amazon Linux version:2 でした! https通信の確認は、毎回ブラウザを開いたときにURLの横に「保護されていない通信です」と表示されることから確認しています。
hoshi-takanori

2021/03/04 07:47

それはどんな URL にアクセスした結果ですか? まさか http://〜 だったりしませんよね?
TaichiYanagiya

2021/03/04 08:06

nginx.conf.default に設定しても有効にならないのでは? nginx.conf または rails.conf に設定するといいと思います。 また、rails.conf の場所は /etc/nginx/nginx.d/ ではなく /etc/nginx/conf.d/ ではないでしょうか?
taba.3011

2021/03/04 11:45

httpsでアクセスするとブラウザが表示されませんでしたが、nginx.conf.defaultに設定していたssl通信の記述を、nginx.confに設定したらhttps通信でブラウザが表示されました! 最後の拡張子がconfのファイルに設定しないと反映されないのですね... 環境や設定に関して理解が曖昧だったのですが、hoshi-takanori様、TaichiYanagiya様コメント頂きありがとうございました!
guest

回答1

0

自己解決

/etc/nginx/nginx.conf.defaultファイル最下部のHTTPSの設定を、/etc/nginx/nginx.confに設定したらうまくいきました

投稿2021/03/04 11:46

taba.3011

総合スコア12

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問