teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

httpのリダイレクトの設定が間違っていたので修正しました

2019/06/07 06:36

投稿

sumagimo
sumagimo

スコア16

title CHANGED
File without changes
body CHANGED
@@ -162,15 +162,15 @@
162
162
 
163
163
  aaa.example.conf
164
164
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
165
- RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
165
+ RewriteRule ^(.*)$ https://aaa.example$1 [R=301,L]
166
166
 
167
167
  www.aaa.example.conf
168
168
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
169
- RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
169
+ RewriteRule ^(.*)$ https://www.aaa.example$1 [R=301,L]
170
170
 
171
171
  www.bbb.example.conf
172
172
  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
173
- RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
173
+ RewriteRule ^(.*)$ https://www.bbb.example$1 [R=301,L]
174
174
 
175
175
  aaa.example-ssl.conf
176
176
  RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外

1

ドメインを例示用に修正、リダイレクト、apacheの設定を追記

2019/06/07 06:36

投稿

sumagimo
sumagimo

スコア16

title CHANGED
File without changes
body CHANGED
@@ -7,28 +7,28 @@
7
7
 
8
8
  ### やりたいこと
9
9
 
10
- aaa.jp
10
+ aaa.example
11
- www.aaa.jp
11
+ www.aaa.example
12
- www.bbb.jp
12
+ www.bbb.example
13
13
  上記3ドメインにLet's Encryptの自動更新のクーロンをセットしたい
14
- ※aaa.jp、www.aaa.jp、www.bbb.jpともに最終的にはccc.jpにリダイレクトさせる
14
+ ※aaa.example、www.aaa.example、www.bbb.exampleともに最終的にはccc.exampleにリダイレクトさせる
15
15
 
16
16
  ### 実行した手順
17
17
 
18
18
  1. httpからhttpsへのリダイレクトを停止し、httpでレスポンスさせておく
19
19
 
20
20
  2. 証明書の取得
21
- $ sudo certbot certonly --webroot -w /var/www/html/ -d aaa.jp
21
+ $ sudo certbot certonly --webroot -w /var/www/html/ -d aaa.example
22
- $ sudo certbot certonly --webroot -w /var/www/html/ -d www.aaa.jp
22
+ $ sudo certbot certonly --webroot -w /var/www/html/ -d www.aaa.example
23
- $ sudo certbot certonly --webroot -w /var/www/html/ -d www.bbb.jp
23
+ $ sudo certbot certonly --webroot -w /var/www/html/ -d www.bbb.example
24
24
 
25
25
  ※下記コマンドがエラーになったため取得と設定を別々に作業することにした
26
- ※$ sudo certbot --apache -d aaa.jp -d www.aaa.jp -d www.bbb.jp
26
+ ※$ sudo certbot --apache -d aaa.example -d www.aaa.example -d www.bbb.example
27
27
 
28
28
  3. 証明書の反映
29
- $ sudo vi aaa.jp-ssl.conf
29
+ $ sudo vi aaa.example-ssl.conf
30
- $ sudo vi www.aaa.jp-ssl.conf
30
+ $ sudo vi www.aaa.example-ssl.conf
31
- $ sudo vi www.bbb.jp-ssl.conf
31
+ $ sudo vi www.bbb.example-ssl.conf
32
32
  それぞれのファイルの証明書の部分を変更
33
33
  SSLCertificateFile /etc/letsencrypt/live/[サーバーのドメイン]/cert.pem
34
34
  SSLCertificateKeyFile /etc/letsencrypt/live/[サーバーのドメイン]/privkey.pem
@@ -37,9 +37,9 @@
37
37
  4. httpからhttpsへのリダイレクトを有効にする
38
38
 
39
39
  5. それぞれのドメインのhttpsを有効にする
40
- $ sudo a2ensite aaa.jp-ssl.conf
40
+ $ sudo a2ensite aaa.example-ssl.conf
41
- $ sudo a2ensite www.aaa.jp-ssl.conf
41
+ $ sudo a2ensite www.aaa.example-ssl.conf
42
- $ sudo a2ensite www.bbb.jp-ssl.conf
42
+ $ sudo a2ensite www.bbb.example-ssl.conf
43
43
  ・設定反映
44
44
  $ sudo apachectl configtest
45
45
  $ sudo /etc/init.d/apache2 reload
@@ -47,10 +47,10 @@
47
47
  6. httpからhttpsへリダイレクトしていることを確認
48
48
 
49
49
  7. 証明書が正しく反映されていることを確認
50
- aaa.jp-ssl.conf
50
+ aaa.example-ssl.conf
51
- www.aaa.jp-ssl.conf
51
+ www.aaa.example-ssl.conf
52
- www.bbb.jp-ssl.conf
52
+ www.bbb.example-ssl.conf
53
- ともに特定のURLはccc.jpにリダイレクトしない除外設定を仕込んで確認
53
+ ともに特定のURLはccc.exampleにリダイレクトしない除外設定を仕込んで確認
54
54
 
55
55
  8. 証明書自動更新のシミュレーション
56
56
  $ sudo certbot renew --dry-run
@@ -63,53 +63,53 @@
63
63
  Saving debug log to /var/log/letsencrypt/letsencrypt.log
64
64
 
65
65
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66
- Processing /etc/letsencrypt/renewal/aaa.jp.conf
66
+ Processing /etc/letsencrypt/renewal/aaa.example.conf
67
67
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68
68
  Cert not due for renewal, but simulating renewal for dry run
69
69
  Plugins selected: Authenticator webroot, Installer None
70
70
  Renewing an existing certificate
71
71
  Performing the following challenges:
72
- http-01 challenge for aaa.jp
72
+ http-01 challenge for aaa.example
73
73
  Waiting for verification...
74
74
  Cleaning up challenges
75
- Attempting to renew cert (aaa.jp) from /etc/letsencrypt/renewal/aaa.jp.conf produced an unexpected error: Failed authorization procedure. aaa.jp (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.jp/ [xxx.xxx.xx.xxx]: "[ccc.jpのindex.htmlの応答]". Skipping.
75
+ Attempting to renew cert (aaa.example) from /etc/letsencrypt/renewal/aaa.example.conf produced an unexpected error: Failed authorization procedure. aaa.example (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.example/ [xxx.xxx.xx.xxx]: "[ccc.exampleのindex.htmlの応答]". Skipping.
76
76
 
77
77
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78
- Processing /etc/letsencrypt/renewal/www.bbb.jp.conf
78
+ Processing /etc/letsencrypt/renewal/www.bbb.example.conf
79
79
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80
80
  Cert not due for renewal, but simulating renewal for dry run
81
81
  Plugins selected: Authenticator webroot, Installer None
82
82
  Renewing an existing certificate
83
83
  Performing the following challenges:
84
- http-01 challenge for www.bbb.jp
84
+ http-01 challenge for www.bbb.example
85
85
  Cleaning up challenges
86
- Attempting to renew cert (www.bbb.jp) from /etc/letsencrypt/renewal/www.bbb.jp.conf produced an unexpected error: Missing command line flag or config entry for this setting:
86
+ Attempting to renew cert (www.bbb.example) from /etc/letsencrypt/renewal/www.bbb.example.conf produced an unexpected error: Missing command line flag or config entry for this setting:
87
- Input the webroot for www.bbb.jp:. Skipping.
87
+ Input the webroot for www.bbb.example:. Skipping.
88
88
 
89
89
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90
- Processing /etc/letsencrypt/renewal/www.aaa.jp.conf
90
+ Processing /etc/letsencrypt/renewal/www.aaa.example.conf
91
91
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92
92
  Cert not due for renewal, but simulating renewal for dry run
93
93
  Plugins selected: Authenticator webroot, Installer None
94
94
  Renewing an existing certificate
95
95
  Performing the following challenges:
96
- http-01 challenge for www.aaa.jp
96
+ http-01 challenge for www.aaa.example
97
97
  Waiting for verification...
98
98
  Cleaning up challenges
99
- Attempting to renew cert (www.aaa.co.jp) from /etc/letsencrypt/renewal/www.aaa.jp.conf produced an unexpected error: Failed authorization procedure. www.aaa.jp (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.jp/ [xx.xxx.xxx.xxx]: "[ccc.jpのindex.htmlの応答]". Skipping.
99
+ Attempting to renew cert (www.aaa.co.example) from /etc/letsencrypt/renewal/www.aaa.example.conf produced an unexpected error: Failed authorization procedure. www.aaa.example (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.example/ [xx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]". Skipping.
100
100
  All renewal attempts failed. The following certs could not be renewed:
101
- /etc/letsencrypt/live/aaa.jp/fullchain.pem (failure)
101
+ /etc/letsencrypt/live/aaa.example/fullchain.pem (failure)
102
- /etc/letsencrypt/live/www.bbb.jp/fullchain.pem (failure)
102
+ /etc/letsencrypt/live/www.bbb.example/fullchain.pem (failure)
103
- /etc/letsencrypt/live/www.aaa.jp/fullchain.pem (failure)
103
+ /etc/letsencrypt/live/www.aaa.example/fullchain.pem (failure)
104
104
 
105
105
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106
106
  ** DRY RUN: simulating 'certbot renew' close to cert expiry
107
107
  ** (The test certificates below have not been saved.)
108
108
 
109
109
  All renewal attempts failed. The following certs could not be renewed:
110
- /etc/letsencrypt/live/aaa.jp/fullchain.pem (failure)
110
+ /etc/letsencrypt/live/aaa.example/fullchain.pem (failure)
111
- /etc/letsencrypt/live/www.bbb.jp/fullchain.pem (failure)
111
+ /etc/letsencrypt/live/www.bbb.example/fullchain.pem (failure)
112
- /etc/letsencrypt/live/www.aaa.jp/fullchain.pem (failure)
112
+ /etc/letsencrypt/live/www.aaa.example/fullchain.pem (failure)
113
113
  ** DRY RUN: simulating 'certbot renew' close to cert expiry
114
114
  ** (The test certificates above have not been saved.)
115
115
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -118,20 +118,20 @@
118
118
  IMPORTANT NOTES:
119
119
  - The following errors were reported by the server:
120
120
 
121
- Domain: aaa.jp
121
+ Domain: aaa.example
122
122
  Type: unauthorized
123
- Detail: Invalid response from https://ccc.jp/
123
+ Detail: Invalid response from https://ccc.example/
124
- [xxx.xxx.xxx.xxx]: "[ccc.jpのindex.htmlの応答]"
124
+ [xxx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]"
125
125
 
126
126
  To fix these errors, please make sure that your domain name was
127
127
  entered correctly and the DNS A/AAAA record(s) for that domain
128
128
  contain(s) the right IP address.
129
129
  - The following errors were reported by the server:
130
130
 
131
- Domain: www.aaa.jp
131
+ Domain: www.aaa.example
132
132
  Type: unauthorized
133
- Detail: Invalid response from https://ccc.jp/
133
+ Detail: Invalid response from https://ccc.example/
134
- [xxx.xxx.xxx.xxx]: "[ccc.jpのindex.htmlの応答]"
134
+ [xxx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]"
135
135
 
136
136
  To fix these errors, please make sure that your domain name was
137
137
  entered correctly and the DNS A/AAAA record(s) for that domain
@@ -145,9 +145,9 @@
145
145
 
146
146
  ### 対策したこと
147
147
 
148
- aaa.jp.conf
148
+ aaa.example.conf
149
- www.aaa.jp.conf
149
+ www.aaa.example.conf
150
- www.bbb.jp.conf
150
+ www.bbb.example.conf
151
151
  上記に対してサーバの認証で使用する(と思われる)pathをドキュメントルートに作成し、リダイレクトから除外してhttpで反応するようにした
152
152
  除外PATH /var/www/html/.well-known/acme-challenge/
153
153
 
@@ -156,4 +156,76 @@
156
156
 
157
157
  ### 原因と思われること
158
158
 
159
- 証明書の取得でサーバ認証PATHに /var/www/html/ を指定したこと
159
+ 証明書の取得でサーバ認証PATHに /var/www/html/ を指定したこと
160
+
161
+ ### リダイレクトの設定
162
+
163
+ aaa.example.conf
164
+ RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
165
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
166
+
167
+ www.aaa.example.conf
168
+ RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
169
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
170
+
171
+ www.bbb.example.conf
172
+ RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
173
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
174
+
175
+ aaa.example-ssl.conf
176
+ RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
177
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
178
+
179
+ www.aaa.example-ssl.conf
180
+ RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
181
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
182
+
183
+ www.bbb.example-ssl.conf
184
+ RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
185
+ RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]
186
+
187
+ ### apacheの設定
188
+
189
+ apache2.conf
190
+
191
+ DefaultRuntimeDir ${APACHE_RUN_DIR}
192
+ PidFile ${APACHE_PID_FILE}
193
+ Timeout 300
194
+ KeepAlive On
195
+ MaxKeepAliveRequests 100
196
+ KeepAliveTimeout 5
197
+ User ${APACHE_RUN_USER}
198
+ Group ${APACHE_RUN_GROUP}
199
+ HostnameLookups Off
200
+ ErrorLog ${APACHE_LOG_DIR}/error.log
201
+ LogLevel warn
202
+ IncludeOptional mods-enabled/*.load
203
+ IncludeOptional mods-enabled/*.conf
204
+ Include ports.conf
205
+ <Directory />
206
+ Options FollowSymLinks
207
+ AllowOverride None
208
+ Require all denied
209
+ </Directory>
210
+
211
+ <Directory /usr/share>
212
+ AllowOverride None
213
+ Require all granted
214
+ </Directory>
215
+
216
+ <Directory /var/www/>
217
+ Options Indexes FollowSymLinks
218
+ AllowOverride None
219
+ Require all granted
220
+ </Directory>
221
+ AccessFileName .htaccess
222
+ <FilesMatch "^.ht">
223
+ Require all denied
224
+ </FilesMatch>
225
+ LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
226
+ LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
227
+ LogFormat "%h %l %u %t \"%r\" %>s %O" common
228
+ LogFormat "%{Referer}i -> %U" referer
229
+ LogFormat "%{User-agent}i" agent
230
+ IncludeOptional conf-enabled/*.conf
231
+ IncludeOptional sites-enabled/*.conf