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

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

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

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

941閲覧

サイトをhttps化したい

ETO3

総合スコア45

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2022/06/09 01:56

さくらVPSを使用しています。
centos7でdocker を動かしサイトを運用しています。
dockerではphp,web,mariadb,phpmyadminの4つのコンテナが動いています。
https化しようと思ってるのですがなかなか上手くいかず手詰まっています。
ご助力頂きたいです。

現状
普通のhttpでサイトは開ける状況です。
httpsで接続すると「接続が拒否されました。」と出ます。

やったこと

Let’s Encryptでssl証明ができるとあるので手順を調べやろうとしていました。
まずはcertbotを使うそうなので試してみました。

# certbot --apache -d [*********].vs.sakura.ne.jp

上記のコマンドを走らせたところ以下のように帰っってきました。

# certbot --apache -d [*********].vs.sakura.ne.jp Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Requesting a certificate for [*********].vs.sakura.ne Performing the following challenges: http-01 challenge for [*********].vs.sakura.ne Error while running apachectl graceful. Job for httpd.service invalid. Unable to restart apache using ['apachectl', 'graceful'] Error while running apachectl restart. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. Cleaning up challenges Error while running apachectl graceful. Job for httpd.service invalid. Unable to restart apache using ['apachectl', 'graceful'] Error while running apachectl restart. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. Encountered exception during recovery: MisconfigurationError: Error while running apachectl restart. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. Error while running apachectl restart. Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

上記の通りに systemctl status httpd.serviceを入力してみたら以下のようになりました。

# systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since 水 2022-06-08 16:35:13 JST; 1h 27min ago Docs: man:httpd(8) man:apachectl(8) Process: 985 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 985 (code=exited, status=1/FAILURE) 6月 08 16:35:13 [*********].vs.sakura.ne.jp systemd[1]: Starting The Apache HTTP Server... 6月 08 16:35:13 [*********].vs.sakura.ne.jp httpd[985]: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf/httpd.conf:355 6月 08 16:35:13 [*********].vs.sakura.ne.jp httpd[985]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 6月 08 16:35:13 [*********].vs.sakura.ne.jp httpd[985]: no listening sockets available, shutting down 6月 08 16:35:13 [*********].vs.sakura.ne.jp httpd[985]: AH00015: Unable to open logs 6月 08 16:35:13 [*********].vs.sakura.ne.jp systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE 6月 08 16:35:13 [*********].vs.sakura.ne.jp systemd[1]: Failed to start The Apache HTTP Server. 6月 08 16:35:13 [*********].vs.sakura.ne.jp systemd[1]: Unit httpd.service entered failed state. 6月 08 16:35:13 [*********].vs.sakura.ne.jp systemd[1]: httpd.service failed.

(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
6月 08 16:35:13 [*********].vs.sakura.ne.jp httpd[985]: no liste
とあるのでなんとなく80番ポートが使用されているので使えないんだろうなと言うのはわかるのですが、
80番はdocker のwebコンテナで使用しています。
dockerのコンテナを落とすわけにもいかない気がするのですが、
この場合どうしたら良いのでしょう?

質問内容

上記のようにサーバー内でdocekrを動かしている場合どのようにhttps化すれば良いのでしょうか?
方針がわからず困っています。
ご助力のほどよろしくお願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

一番楽なのはnginx-proxyを使うことだと思います。
コンテナに入ってコマンド叩くとかもほとんどしなかった気がします。

参考)
https://it-web-life.com/docker-ssl-nginx-proxy/
https://qiita.com/ohhara_shiojiri/items/193d416ee8ba70d656aa

他にもcertbotのDockerイメージを使う方法もあるみたいです(私は試したことないのでよく分かりませんが)
https://blog.panicblanket.com/archives/6759

ご自分の環境に合わせて良さげなのを選ばれたら良いと思います。

投稿2022/06/09 02:29

AbeTakashi

総合スコア4537

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

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

ETO3

2022/06/10 04:22

参考リンクありがとうございます!やってみます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問