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

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

新規登録して質問してみよう
ただいま回答率
85.48%
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)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

4017閲覧

Let's Encryptを使用して無料でSSL化したいが本番環境にアクセスできなくなりました。

jooooz_jjj

総合スコア4

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)とは、暗号化されたプロトコルで、インターネット上での通信セキュリティを提供しています。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

1クリップ

投稿2019/10/19 07:13

編集2019/10/19 08:02

前提・実現したいこと

・前提
http://xxxxxxxxx.comの状態でのアクセスはできていました。
無料でSSL化できるLet's Encryptを使用しております。
ポートフォリオはrailsで作成しております。

・実現したいこと
自身で作成したポートフォリオをSSL化(https://xxxxxxxxxx.com)の状態で
アクセスできるようにしたい

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

https://xxxxxxxxx.comとURLをブラウザに打ち込むとロード状態でくるくると読み込み中になり、
ページが表示されずURL横にはこのサイトへの接続は保護されていませんと出ている。
PCはmacbookproを使用しており、サーバーはnginxを使っております。

該当のソースコード

下記qiitaの記事を参考に進めていきました。
https://qiita.com/MuuKojima/items/f2b80a77c13900b293e4

#移動
cd /usr/local/

#リポジトリをクローン
sudo git clone https://github.com/certbot/certbot

#実行
sudo ./letsencrypt-auto --debug

How would you like to authenticate and install certificates?
1: Apache Web Server plugin (apache)
2: Nginx Web Server plugin (nginx)


Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

と聞かれたので2を選択。

Which names would you like to activate HTTPS for?


1: (自身のドメイン名).com


と聞かれたので1を選択

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/melhealhabit.com.conf)

What would you like to do?


1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)


と聞かれた(おそらく確認のために2回目の実行をしようとした)ので、2を選択。

Renewing an existing certificate
Deploying Certificate to VirtualHost /etc/nginx/conf.d/melhealhabit.confと表示される。

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.


1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
と聞かれたので1を選択。

Future versions of Certbot will automatically configure the webserver so that all requests redirect to secure HTTPS access. You can control this behavior and disable this warning with the --redirect and --no-redirect flags.


Your existing certificate has been successfully renewed, and the new certificate
has been installed.

The new certificate covers the following domains: https://melhealhabit.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=melhealhabit.com


IMPORTANT NOTES:

  • Congratulations! Your certificate and chain have been saved at:
    /etc/letsencrypt/live/melhealhabit.com/fullchain.pem
    Your key file has been saved at:
    /etc/letsencrypt/live/melhealhabit.com/privkey.pem
    Your cert will expire on 2020-01-17. To obtain a new or tweaked
    version of this certificate in the future, simply run
    letsencrypt-auto again with the "certonly" option. To
    non-interactively renew all of your certificates, run
    "letsencrypt-auto renew"
  • If you like Certbot, please consider supporting our work by:

と表示されて、正常に証明書がインストールできたと思い、テストをするべきと記載されていたので、
サーバーテストをしてみるとAssessment failed: Unable to connect to the serverという
メッセージが表示されてサーバーに接続できません。

試したこと

上記の時点で接続できなくっていたとは思うのですが、一度qiitaの記事通りに通して実行していきました。

#実行
$sudo ./certbot-auto -debug

How would you like to authenticate and install certificates?


1: Apache Web Server plugin (apache)
2: Nginx Web Server plugin (nginx)


と聞かれたので、2を選択。

Obtaining a new certificate
An unexpected error occurred:
The server will not issue certificates for the identifier :: Error creating new order :: Cannot issue for "ebug": DNS name does not have enough labels
Please see the logfiles in /var/log/letsencrypt for more details.

このようなエラーが表示されました。

そのままqiitaの記事に沿って進めました。
#nginxを停止。
&sudo service nginx stop
#SSL証明書を発行。
$sudo ./certbot-auto certonly

How would you like to authenticate with the ACME CA?


1: Apache Web Server plugin (apache)
2: Nginx Web Server plugin (nginx)
3: Spin up a temporary webserver (standalone)
4: Place files in webroot directory (webroot)


と聞かれたので、2を選択。

Plugins selected: Authenticator nginx, Installer None
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel): melhealhabit.com
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/melhealhabit.com.conf)

と表示されました。既に要求したドメインの証明書はあるよと言われているみたいです。

What would you like to do?


1: Keep the existing certificate for now
2: Renew & replace the cert (limit ~5 per 7 days)


と聞かれたので、1を選択しました。


Certificate not yet due for renewal; no action taken.


と表示されました。

#nginx再起動
sudo service nginx restart

nginxの設定も一度編集し、SSLを読み込むようにしたのですが、
正常にサイトにアクセスできない問題が解決しないために、
編集前の状態に戻しています。

#Nginxの状態追記

upstream puma {

server unix:///home/ec2-user/first_portfolio/tmp/sockets/puma.sock;

}

server {

server_name melhealhabit.com;

root /home/ec2-user/first_portfolio/public;

access_log /var/log/nginx/access.log main;

error_log /var/log/nginx/error.log;

sendfile on;

  tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 65;

types_hash_max_size 2048;

include /etc/nginx/mime.types;

location / {

proxy_pass http://puma; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host;

     proxy_set_header X-Real-IP $remote_addr;

proxy_redirect off; proxy_connect_timeout 30; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /home/ec2-user/first_portfolio/public; }

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/melhealhabit.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/melhealhabit.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = melhealhabit.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80;

server_name melhealhabit.com;
return 404; # managed by Certbot

}

     

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

 IPアドレスを直接ブラウザに打ち込むとnginxへようこそのページに遷移します。
http://xxxxxxxxx.comでアクセスしようとすると同様にロード状態になり、最終的に応答時間が長すぎるために、
エラーページが表示されます。

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

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

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

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

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

CHERRY

2019/10/19 07:39

nginx の設定はどうなっているでしょうか?
jooooz_jjj

2019/10/19 08:03

コメントいただきありがとうございます。 nginxの設定を追記させていただきました。 ご確認よろしくお願いいたします。
CHERRY

2019/10/19 08:07

ログファイルには、どのようなメッセージが記録されているのでしょうか?
jooooz_jjj

2019/10/19 08:16

アクセスログはこのようになっております。 104.237.145.123 - - [19/Oct/2019:06:44:51 +0000] "GET / HTTP/1.0" 200 3770 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:51 +0000] "Gh0st\xAD\x00\x00\x00\xE0\x00\x00\x00x\x9CKS``\x98\xC3\xC0\xC0\xC0\x06\xC4\x8C@\xBCQ\x96\x81\x81\x09H\x07\xA7\x16\x95e&\xA7*\x04$&g+\x182\x94\xF6\xB000\xAC\xA8rc\x00\x01\x11\xA0\x82\x1F\x5C`&\x83\xC7K7\x86\x19\xE5n\x0C9\x95n\x0C;\x84\x0F3\xAC\xE8sch\xA8^\xCF4'J\x97\xA9\x82\xE30\xC3\x91h]&\x90\xF8\xCE\x97S\xCBA4L?2=\xE1\xC4\x92\x86\x0B@\xF5`\x0CT\x1F\xAE\xAF]" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:51 +0000] "145.ll|'|'|SGFjS2VkX0Q0OTkwNjI3|'|'|WIN-JNAPIER0859|'|'|JNapier|'|'|19-02-01|'|'||'|'|Win 7 Professional SP1 x64|'|'|No|'|'|0.7d|'|'|..|'|'|AA==|'|'|112.inf|'|'|SGFjS2VkDQoxOTIuMTY4LjkyLjIyMjo1NTUyDQpEZXNrdG9wDQpjbGllbnRhLmV4ZQ0KRmFsc2UNCkZhbHNlDQpUcnVlDQpGYWxzZQ==12.act|'|'|AA==" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:52 +0000] "H\x00\x00\x00tj\xA8\x9E#D\x98+\xCA\xF0\xA7\xBBl\xC5\x19\xD7\x8D\xB6\x18\xEDJ\x1En\xC1\xF9xu[l\xF0E\x1D-j\xEC\xD4xL\xC9r\xC9\x15\x10u\xE0%\x86Rtg\x05fv\x86]%\xCC\x80\x0C\xE8\xCF\xAE\x00\xB5\xC0f\xC8\x8DD\xC5\x09\xF4" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:52 +0000] "HELP" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:52 +0000] "\x1B\x84\xD5\xB0]\xF4\xC4\x93\xC50\xC2X\x8C\xDA\xB1\xD7\xAC\xAFn\x1D\xE1\x1E\x1A3*\x85\xB7\x1D'\xB1\xC9k\xBF\xF0\xBC" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:53 +0000] "batman" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:53 +0000] "\x16\x03\x01\x00t\x01\x00\x00p\x03\x01YF}\xF6\x7F3\xD3\xA2'O\xAE\xB6\x041p\x87F\xE5\xA6\xA2\x18\xD1\x0B}\x0C\x9FO)u\xFE\xB1\xD9\x00\x00\x18\xC0\x14\xC0\x13\x005\x00/\xC0" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:53 +0000] "\x01\x82\x00\x00\x00\x01,\xEF:\xE7\x89\xFEH\xAF\xAC\xF8\xC1Pq\xD7\xC3\xE8S\x8A\xD6:\x17\xD93\x14o)S}\xBB\xBB\x97b\xCE\xB6\x0B\x9B\xB97>\x01\xCFv\xAE\xA0E\xB6D\xEA\xE1\xEAA\xC4\xDB\xEE\x09\xAC\xFB\xF0\x84)k\xBBc\x18]V\x85V\xC5_\x05T\x0Bt\xC4\x0B\xBE\xB5w\xBCM=[1\xE1\x06\x9C\xFD\xD3g^\xE3\x01\x9BK\xD7\xFC>\xFFk\xAF\x95\x99\xFB\xDBH\x90\x8BD\x88`k\x92\xF5e\x1C\xAA\xBB{_LP\x15\x85\x1E\x0E\x8F\xDD\xC5J" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:54 +0000] "\xBD\xFF\x9E\xFFE\xFF\x9E\xFF\xBD\xFF\x9E\xFF\xA4\xFF\x86\xFF\xC4\xFF\xBE\xFF\xC7\xFF\xDB\xFF\xEE\xFFx\x5Cd9\xFF\xED\xFF\xA4\xFF\x9D\xFF\xCF\xFF\xD8\xFF\xE5\xFF\x04\xFF\x12\xFF0\xFF\xB1\xFF\xBD\xFF\xE7\xFF\xE2\xFF\xDD\xFF\xDC\xFF\xDE\xFF\xC8\xFF\xCC\xFF\xBE\xFF\xF8\xFF&\xFF\x01\xFF\x0F\xFF\xF5\xFF\x06\xFF\xFF\xFF\xF7\xFF!\xFF\xDE\xFF\x02\xFF&\xFF\x0C\xFF\x01\xFF\xF5\xFF" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:54 +0000] "A\x00\x00\x00\x03fH\xBBd~\x8E\xFC\x94g\xD2\xDB\xFC\xEE\x8D\xFF\x98 \xB1\xBET\xA4\x9AZ\x9A\xA0?\x90\xE0\xF2t0\x5C\xED\xAE\xACX\x98\xDEJ\xEC\xF2\xC8\x9Cl\xD0\x9C\xC0\xE0\x98\x12\x8F\xE7\xCB\x8F\xA1\xA3\x16\xF1J\xA9<\xBD\xDA`" 400 173 "-" "-" "-" 104.237.145.123 - - [19/Oct/2019:06:44:54 +0000] "\x09\x12;Bo3\xA2D\xFD\x01\x86si=\xAE\x12\xBB\xC6\x19\xFD\x1A:\xF3\x11\xC9\xAE\xDA<0\xBC8\x81\x9E\x00\x0F\xCAN\xFB\x05\xC6\xDE\xB7<oN\x01\xA2\x87\x82\xF5/\x8E\xED*\x1F\x0E\xB7C\x0C\xA04]\xBD\x80PVf\x1A\x11\xAF\xF5\xC8\xA3\x16+b\xB1\xD7" 400 173 "-" "-" "-" 139.162.144.244 - - [19/Oct/2019:06:45:06 +0000] "GET / HTTP/1.0" 200 3770 "-" "-" "-" 111.239.162.112 - - [19/Oct/2019:07:09:59 +0000] "GET /favicon.ico HTTP/1.1" 404 3696 "http://13.113.179.169/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36" "-" 5.202.159.103 - - [19/Oct/2019:07:39:14 +0000] "GET / HTTP/1.1" 200 3770 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "-" 220.145.16.201 - - [19/Oct/2019:08:06:20 +0000] "GET / HTTP/1.1" 301 185 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15" "-" 103.206.102.24 - - [19/Oct/2019:08:06:32 +0000] "GET / HTTP/1.1" 200 3770 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "-" エラーログはこのようになっております。 2019/10/19 06:21:43 [notice] 11378#0: signal process started 2019/10/19 07:09:59 [error] 11793#0: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 111.239.162.112, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "13.113.179.169", referrer: "http://13.113.179.169/"
guest

回答1

0

自己解決

解決しました。

対象のEC2インスタンスのポート解放をしてなかったためサイトに接続できませんでした・

対象のインスタンスの管理画面からセキュリティグループ設定で
ルールの追加をしてタイプ「HTTPS」、ポート範囲「443」にすることで解決しました。
その後ページに接続できたのですが、ログインができなくなりましたが、
その問題はnginxの設定に問題があったようで以下で解決しました。

X-Forwarded-Protoヘッダーの設定を変更し、
「ユーザのリクエストが使用したHTTPスキームを指定する」ように修正。
下記のように記述
proxy_set_header X-Forwarded-Proto $scheme;

これでSSL化できて問題なく動作できるようになりました。

コメントいただいた方ありがとうございました。
日々精進してまいります。

投稿2019/10/19 11:12

編集2019/10/19 11:14
jooooz_jjj

総合スコア4

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問