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

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

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

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

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

SSL

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

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

Q&A

2回答

4485閲覧

さくらVPSのSSL化

falconHM

総合スコア6

HTTPS

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

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

SSL

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

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

VPS

VPS(バーチャル・プライベート・サーバ)は、仮想化されたサーバをレンタルするサービスで、共有サーバでありながら専門サーバと同等の機能を果たします。物理的な専門サーバより安価で提供できるメリットがあります。

0グッド

1クリップ

投稿2018/09/11 14:31

編集2022/01/12 10:55

初めてサーバーを借り、SSL化をしようと思い奮闘中です。
ドメインを取得し、ドメイン名でのアクセスは出来ている状態です。
httpsでのアクセスもiptablesを443の設定をしアクセスは出来ている状態です。
(保護されていない通信状態)

ssl証明書を取得しさくらの管理画面の連携は済んでいます。
下記ページを参考に「中間証明書をサーバに配置」まで実施しました。
さくらVPS(CentOS7.2+Apache2.4)でSSL証明書(JPRS)を発行してhttpsにするまで

で、この後の対応として、「Apacheに証明書のパスを配置」をやろうと思っているのですが、
うまくいきません。。。

まずhttpd.confに下記を入れました。

#一番最後に記載 Include conf.d/*.conf

で、色々調べたところ、ssl.confの<VirtualHost _default_:443>から閉じタグまでコメントアウトするのかと思いコメントアウトしました。
そしてvhost.confを作成し、下記を記載しました。

NameVirtualHost *:443 <VirtualHost *:443> SSLEngine on SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt SSLCertificateChainFile /etc/httpd/conf/ssl.crt/internal.crt ServerName exsample.com #こちらは変更済みです DocumentRoot /var/www/html/ <Directory "/var/www/html/"> AllowOverride All Options Indexes FollowSymLinks </Directory> </VirtualHost>

ここでサーバー再起動をするとエラーになってしまいます。

httpd を停止中: [ OK ] httpd を起動中: [Tue Sep 11 23:22:56 2018] [warn] module php7_module is already loaded, skipping [Tue Sep 11 23:22:56 2018] [warn] module ssl_module is already loaded, skipping [Tue Sep 11 23:22:56 2018] [warn] NameVirtualHost *:443 has no VirtualHosts (98)Address already in use: make_sock: could not bind to address 0.0.0.0:443 no listening sockets available, shutting down Unable to open logs [失敗]

NameVirtualHostのエラーをググると「NameVirtualHost *:443」を2つ以上設定しているらしいのですが、
vhost.confにしか記載していない状態です。。。
その後vhost.confやssl.confを色々いじってみたのですが解決が出来ておりません。

何か手順を間違えている箇所ありますでしょうか。。。?m(_ _)m


9/12追記します。
httpd.confのInclude conf.d/*.confをInclude conf.d/vhost.confにしてみたらエラーが下記だけになりました。

[warn] NameVirtualHost *:443 has no VirtualHosts

これに関して検索をしてみても記述に間違いがあるような箇所を発見出来ません。。。


10/2追記します。
サーバーの再起動はできるようになったのですが、error_logに下記エラーが出力されていました。
```
[Tue Oct 02 20:05:10 2018] [notice] caught SIGTERM, shutting down
[Tue Oct 02 20:05:10 2018] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Oct 02 20:05:19 2018] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Tue Oct 02 20:05:19 2018] [notice] Digest: generating secret for digest authentication ...
[Tue Oct 02 20:05:19 2018] [notice] Digest: done
[Tue Oct 02 20:05:19 2018] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips configured -- resuming normal operations
```
[warn] Init: Session Cache is not configured [hint: SSLSessionCache]
上記で色々検索して解決策を見ているのですが解決に至っていません。。。
現在のvhost.confは以下になります。
```

setting for ssl

LoadModule ssl_module modules/mod_ssl.so

#Listen 443
#NameVirtualHost *:443

<IfModule mod_ssl.c>

<VirtualHost *:443>
SSLEngine on
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
SSLCertificateChainFile /etc/httpd/conf/ssl.crt/internal.crt

ServerName falcon.click DocumentRoot /var/www/html/ <Directory "/var/www/html/"> AllowOverride All Options Indexes FollowSymLinks </Directory>
</VirtualHost> </IfModule> ``` 現在のiptablesは下記になります。 ``` Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED 2 ACCEPT icmp -- anywhere anywhere 3 ACCEPT all -- anywhere anywhere 4 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh 5 ACCEPT tcp -- anywhere anywhere tcp dpt:http 6 ACCEPT tcp -- anywhere anywhere tcp dpt:https 7 ACCEPT tcp -- anywhere anywhere tcp dpt:61203 8 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
```
色々と調べてはいるのですが、、、何かエラーの原因になる箇所わかりますでしょうか。。。?

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

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

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

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

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

CHERRY

2018/09/11 21:03

apachectl configtest の結果はどうでしょうか?
falconHM

2018/09/12 14:35

Orlofskyさん ご指摘ありがとうございます!修正しました!
falconHM

2018/09/12 14:36

CHERRYさん 実行結果はこちらになります![Wed Sep 12 23:20:36 2018] [warn] module php7_module is already loaded, skipping [Wed Sep 12 23:20:36 2018] [warn] module ssl_module is already loaded, skipping [Wed Sep 12 23:20:36 2018] [warn] NameVirtualHost *:443 has no VirtualHosts Syntax OK
guest

回答2

0

手作業で行うよりも、certbot-auto を使うと楽ですよ。

certbot-auto を利用して、SSLにすることは、対話形式で応答するだけで、半自動で設定可能です。
Certbotをダウンロードして、実行権限を付与。
certbot-auto をダウンロードして、実行権限を付与。

bash

1cd ~ 2wget https://dl.eff.org/certbot-auto 3chmod a+x certbot-auto

Certbotを実行。
certbot-autoを実行。

bash

1./certbot-auto

SSLサーバ証明書の設定
Apacheとnginxのどちらを使うか質問される場合。Apacheしかない場合は多分聞かれない。

bash

1How would you like to authenticate and install certificates? 2------------------------------------------------------------------------------- 31: Apache Web Server plugin - Beta (apache) 42: Nginx Web Server plugin - Alpha (nginx) 5------------------------------------------------------------------------------- 6Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

メールアドレスを入力します。

bash

1Enter email address (used for urgent renewal and security notices) (Enter 'c' to 2cancel): xxxxxxxxx@xxxxxx.com

規約に同意するよう求められます。「A」を入力。

bash

1Please read the Terms of Service at 2https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree 3in order to register with the ACME server at 4https://acme-v01.api.letsencrypt.org/directory 5------------------------------------------------------------------------------- 6(A)gree/(C)ancel: A

メールアドレスを電子フロンティア財団に共有するか質問されます。
財団からメールが届くらしいのですが、不要なので「N」を入力。

bash

1------------------------------------------------------------------------------- 2Would you be willing to share your email address with the Electronic Frontier 3Foundation, a founding partner of the Let's Encrypt project and the non-profit 4organization that develops Certbot? We'd like to send you email about EFF and 5our work to encrypt the web, protect its users and defend digital rights. 6------------------------------------------------------------------------------- 7(Y)es/(N)o: N

Webサーバに複数のサイトが同居している場合、どのサイトをHTTPS化するか質問されます。
対象の番号を入力。一つしかない場合は、多分聞かれない。

bash

1Which names would you like to activate HTTPS for? 2------------------------------------------------------------------------------- 31: example.com 42: www.example.com 5------------------------------------------------------------------------------- 6Select the appropriate numbers separated by commas and/or spaces, or leave input 7blank to select all options shown (Enter 'c' to cancel): 1

少し待つと、自動で証明書の取得が進みます。
HTTPSへのリダイレクト設定をするか指定します。今回のばあい、リダイレクトするので、2で応答する。

bash

1Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. 2------------------------------------------------------------------------------- 31: No redirect - Make no further changes to the webserver configuration. 42: Redirect - Make all requests redirect to secure HTTPS access. Choose this for 5new sites, or if you're confident your site works on HTTPS. You can undo this 6change by editing your web server's configuration. 7------------------------------------------------------------------------------- 8Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

「Congratulations!」と表示されたら、設定完了です。

投稿2018/09/18 15:20

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

falconHM

2018/10/01 15:18

ご返信が遅くなってしまいすみません! こんな方法があるんですね。。。(凄い) 後ちょっとで出来そうなんですが無理だった場合こちらの方法を試させていただきます!
guest

0

「NameVirtualHost *:443」は必要ないです。
設定から削除してください

また、ssl.confをデフォルトに戻してください

投稿2018/09/14 11:01

hide0527

総合スコア144

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

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

falconHM

2018/09/15 01:35

ご回答ありがとうございます! ご指摘いただきました内容を修正したところエラーが変わりました。 ``` Syntax error on line 40 of /etc/httpd/conf.d/vhost.conf: Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration ``` 調べたところ下記記述が無いとの事でしたのでvhost.confに記述しました。 LoadModule ssl_module modules/mod_ssl.so sudo service httpd restartで再起動をしたところエラーは出なくなりましたが起動に失敗してしまいます。。。 ``` httpd を停止中: [ OK ] httpd を起動中: [失敗] ``` 試しにvhost.confの中身を全てコメントアウトすると再起動は成功します。 vhost.confの中身は問題無いと思うので証明書の設定がうまくいっていなくてこけているのでしょうか? 一度見直してみます。。。 念のため下記に現在のvhost.confの中身を記載させていただきます。 ``` ## setting for ssl LoadModule ssl_module modules/mod_ssl.so #Listen 443 #NameVirtualHost *:443 <VirtualHost *:443> SSLEngine on SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt SSLCertificateChainFile /etc/httpd/conf/ssl.crt/internal.crt ServerName exsample.com#ここは変更しています DocumentRoot /var/www/html/ <Directory "/var/www/html/"> AllowOverride All Options Indexes FollowSymLinks </Directory> </VirtualHost> ```
hide0527

2018/09/15 05:12

以下のように、<Ifmodule>の記載を追加してみてください <IfModule mod_ssl.c> ←追加 <VirtualHost *:443> SSLEngine on SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt SSLCertificateChainFile /etc/httpd/conf/ssl.crt/internal.crt ServerName exsample.com#ここは変更しています DocumentRoot /var/www/html/ <Directory "/var/www/html/"> AllowOverride All Options Indexes FollowSymLinks </Directory> </VirtualHost> </IfModule> ←追加 また、error.logには何かメッセージが出力されているか確認をお願いいたします
falconHM

2018/09/18 15:14

再起動ができるようになりました! ご回答頂いた内容を打ち込み、エラーログを確認したら [error] Init: Unable to read server certificate from file /etc/httpd/conf/ssl.crt/server.crt と言うエラーが出ましたが、証明書を見直したところ記述漏れ(コピペミス)がありましたので、 それを直したら再起動出来ました! 早速ブラウザアクセスしようと思ったのですが、 httpアクセスは問題無いですがhttpsでのアクセスが出来ない状態でした。。。 以前iptablesで443設定したのでアクセスは出来ていた(危険ですが繋げますか状態)ので、 再度エラーログ等見てみようと思います!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問