ebb5f6fb6d953f6cd4fd1702fb462a93e073d795
Linux/Apache/Home.md
... | ... | @@ -1,5 +1,8 @@ |
1 | 1 | [[_TOC_]] |
2 | -- [[Perl/ApacheErrorLogFormatter]] |
|
2 | +- [[mod_geoip]] |
|
3 | +- [[mod_security]] |
|
4 | +- [[mod_ssl]] |
|
5 | +- [[ApacheErrorLogFormatter|/Perl/ApacheErrorLogFormatter]] |
|
3 | 6 | |
4 | 7 | # ドキュメント |
5 | 8 | - [Apache HTTP Server Documentation](http://httpd.apache.org/docs/) |
... | ... | @@ -16,39 +19,39 @@ |
16 | 19 | |
17 | 20 | # Apache用モジュールをコンパイルできるようにする |
18 | 21 | - httpd-devel (apxs) をインストールしておく。 |
19 | -``` |
|
20 | -# yum install httpd-devel |
|
21 | -``` |
|
22 | + ``` |
|
23 | + # yum install httpd-devel |
|
24 | + ``` |
|
22 | 25 | |
23 | 26 | # バーチャルホスト設定 |
24 | 27 | - [バーチャルホスト説明書](http://httpd.apache.org/docs/current/vhosts/) |
25 | 28 | |
26 | 29 | ## 設定 |
27 | 30 | - /etc/httpd/conf.d/VirtualHosts.conf |
28 | -```apache |
|
29 | -# Use name-based virtual hosting. |
|
30 | -NameVirtualHost *:80 |
|
31 | - |
|
32 | -<VirtualHost *:80> |
|
33 | - ServerName www.takeash.net |
|
34 | - DocumentRoot /var/www/html/ |
|
35 | -</VirtualHost> |
|
36 | - |
|
37 | -<VirtualHost *:80> |
|
38 | - ServerName vh1.takeash.net |
|
39 | - DocumentRoot /var/www/vh1-html/ |
|
40 | - <Directory "/var/www/vh1-html"> |
|
41 | -# AllowOverride All |
|
42 | - </Directory> |
|
43 | -</VirtualHost> |
|
44 | -``` |
|
31 | + ```apache |
|
32 | + # Use name-based virtual hosting. |
|
33 | + NameVirtualHost *:80 |
|
34 | + |
|
35 | + <VirtualHost *:80> |
|
36 | + ServerName www.takeash.net |
|
37 | + DocumentRoot /var/www/html/ |
|
38 | + </VirtualHost> |
|
39 | + |
|
40 | + <VirtualHost *:80> |
|
41 | + ServerName vh1.takeash.net |
|
42 | + DocumentRoot /var/www/vh1-html/ |
|
43 | + <Directory "/var/www/vh1-html"> |
|
44 | + # AllowOverride All |
|
45 | + </Directory> |
|
46 | + </VirtualHost> |
|
47 | + ``` |
|
45 | 48 | |
46 | 49 | ## エラー対策 |
47 | 50 | - バーチャルホストが表示されない。 |
48 | 51 | - エラーメッセージ |
49 | -``` |
|
50 | -[warn] _default_ VirtualHost overlap on port 80, the first has precedence |
|
51 | -``` |
|
52 | + ``` |
|
53 | + [warn] _default_ VirtualHost overlap on port 80, the first has precedence |
|
54 | + ``` |
|
52 | 55 | - 原因<br /> |
53 | 56 | NameVirtualHost ディレクティブが設定されていない。 |
54 | 57 | - 対処<br /> |
... | ... | @@ -59,588 +62,24 @@ httpd.conf を修正するより conf.d に VirtualHosts.conf として専用の |
59 | 62 | - [認証、承認、アクセス制御](http://httpd.apache.org/docs/current/howto/auth.html) |
60 | 63 | - [mod_auth_digest](http://httpd.apache.org/docs/current/mod/mod_auth_digest.html) |
61 | 64 | - レルム/ユーザ/パスワード追加 |
62 | -``` |
|
63 | -htdigest [-c] passwdfile <realm> <username> |
|
64 | -``` |
|
65 | - - /etc/httpd/conf.d/DigestAuth.conf |
|
66 | -```apache |
|
67 | -<Directory "/var/www/html/Download/<realm>"> |
|
68 | - AllowOverride AuthConfig |
|
69 | - AuthType Digest |
|
70 | - AuthName "<realm>" |
|
71 | - AuthUserFile /var/www/passwd/passwords_digest |
|
72 | - Require user <username> |
|
73 | - Options None |
|
74 | - Options Indexes |
|
75 | - DirectoryIndex index.html index.htm index.php |
|
76 | - Order allow,deny |
|
77 | - Allow from all |
|
78 | -</Directory> |
|
79 | -``` |
|
80 | - |
|
81 | -# mod_ssl |
|
82 | -- インストール |
|
83 | -``` |
|
84 | -# yum install mod_ssl |
|
85 | -``` |
|
86 | - |
|
87 | -## 自己署名証明書使用 |
|
88 | - |
|
89 | -- SAN 項目を追加した設定ファイルを作成。 |
|
90 | -``` |
|
91 | -# cd /etc/pki/tls/ |
|
92 | -# cp openssl.cnf openssl-san.cnf |
|
93 | -``` |
|
94 | - |
|
95 | -- openssl.cnf と openssl-san.cnf の差分 |
|
96 | -``` |
|
97 | ---- openssl.cnf |
|
98 | -+++ openssl-san.cnf |
|
99 | -@@ -104,7 +104,7 @@ |
|
100 | - #################################################################### |
|
101 | - [ req ] |
|
102 | - default_bits = 2048 |
|
103 | --default_md = sha1 |
|
104 | -+default_md = sha256 |
|
105 | - default_keyfile = privkey.pem |
|
106 | - distinguished_name = req_distinguished_name |
|
107 | - attributes = req_attributes |
|
108 | -@@ -222,6 +222,11 @@ |
|
109 | - |
|
110 | - basicConstraints = CA:FALSE |
|
111 | - keyUsage = nonRepudiation, digitalSignature, keyEncipherment |
|
112 | -+subjectAltName=@alt_names |
|
113 | -+ |
|
114 | -+[ alt_names ] |
|
115 | -+DNS.1=takeash.net |
|
116 | -+DNS.2=*.takeash.net |
|
117 | - |
|
118 | -[ v3_ca ] |
|
119 | - |
|
120 | -``` |
|
121 | -- 証明書フォルダへ移動 |
|
122 | -``` |
|
123 | -# cd certs/ |
|
124 | -``` |
|
125 | - |
|
126 | -- サーバー用秘密鍵作成 (server.key) |
|
127 | -``` |
|
128 | -# openssl genrsa -aes128 2048 > server.key |
|
129 | -``` |
|
130 | - |
|
131 | -- パスフレーズ削除<br /> |
|
132 | -httpd 再起動時にパスフレーズが要求されないようにするため。 |
|
133 | -``` |
|
134 | -# openssl rsa -in server.key -out server.key |
|
135 | -``` |
|
136 | - |
|
137 | -- サーバー用自己署名証明書作成 (server.crt) |
|
138 | -``` |
|
139 | -# openssl req -utf8 -new -key server.key -x509 -days 3650 -out server.crt -set_serial 0 \ |
|
140 | - -subj '/C=JP/ST=Tokyo/L=Chuo-ku/O=TakeAsh.net/CN=takeash.net' -extensions v3_req -config ../openssl-san.cnf |
|
141 | -``` |
|
142 | - - サブジェクト例 (TakeAsh.net) |
|
143 | - |
|
144 | - | 項目 | 用途 | サンプル | |
|
145 | - | --- | --- | --- | |
|
146 | - | C | 国名コード | JP | |
|
147 | - | ST | 都道府県 | Tokyo | |
|
148 | - | L | 区市町村 | Chuo-ku | |
|
149 | - | O | 組織名 | TakeAsh.net | |
|
150 | - | CN | コモンネーム(ドメイン名) | takeash.net | |
|
151 | - - 証明書確認<br /> |
|
152 | -「X509v3 extensions - X509v3 Subject Alternative Name」項目が存在すれば SAN が含まれている。 |
|
153 | -``` |
|
154 | -# openssl x509 -in server.crt -text |
|
155 | -... |
|
156 | - X509v3 Subject Alternative Name: |
|
157 | - DNS:takeash.net, DNS:*.takeash.net |
|
158 | -... |
|
159 | -``` |
|
160 | - |
|
161 | -- /etc/httpd/conf.d/ssl.conf (抜粋) |
|
162 | -``` |
|
163 | -SSLCertificateFile /etc/pki/tls/certs/server.crt |
|
164 | -SSLCertificateKeyFile /etc/pki/tls/certs/server.key |
|
165 | -DocumentRoot "/var/www/html" |
|
166 | -SSLProtocol all -SSLv2 -SSLv3 |
|
167 | -``` |
|
168 | - |
|
169 | -- httpd 再起動 |
|
170 | - - CentOS 6 |
|
171 | -``` |
|
172 | -# service httpd restart |
|
173 | -``` |
|
174 | - - CentOS 7 |
|
175 | -``` |
|
176 | -# systemctl restart httpd |
|
177 | -``` |
|
178 | - |
|
179 | -- 動作テスト |
|
180 | - - https://takeash.net/cgi-bin/etc/PrintEnv.cgi |
|
181 | - - https://www.takeash.net/cgi-bin/etc/PrintEnv.cgi |
|
182 | - |
|
183 | -- [OpenSSL CSR with Alternative Names one-line - End Point Blog](http://blog.endpoint.com/2014/10/openssl-csr-with-alternative-names-one.html) |
|
184 | -- [SAN対応 x.509 証明書を取得するためのCSRを作成する - Qiita](http://qiita.com/saitara/items/eda74ac6a950122b5f31) |
|
185 | -- [subjectAltNameでバーチャルホスト - Kung Noi Blog](http://www.goodnai.com/blog/2010/05/07/subjectaltname%E3%81%A7%E3%83%90%E3%83%BC%E3%83%81%E3%83%A3%E3%83%AB%E3%83%9B%E3%82%B9%E3%83%88/) |
|
186 | -- [Webサーバー間通信内容暗号化(Apache+mod_SSL) - CentOSで自宅サーバー構築](http://centossrv.com/apache-ssl.shtml) |
|
187 | -- [SSL Server Test (Powered by Qualys SSL Labs)](https://www.ssllabs.com/ssltest/) |
|
188 | -- [ssl certificate - how to add subject alernative name to ssl certs? - Stack Overflow](https://stackoverflow.com/questions/%38%37%34%34%36%30%37) |
|
189 | - - keytool -certreq -ext SAN=dns:example.com,ip:192.168.0.1 |
|
190 | - - [keytool(ja)](https://docs.oracle.com/javase/jp/8/docs/technotes/tools/windows/keytool.html) / [keytool(en)](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html) |
|
191 | - |
|
192 | -## Certbot 使用 |
|
193 | -- Certbot 使用前準備 |
|
194 | - - ホスト名が正引きできること。(ワイルドカード不可) |
|
195 | - - バーチャルホストのサーバ名と要求するドメイン名のどれかが一致すること。 |
|
196 | - - https でアクセス可能になっていること。 |
|
197 | - - https ポート解放 |
|
198 | -``` |
|
199 | -# firewall-cmd --add-service=https --permanent |
|
200 | -``` |
|
201 | - |
|
202 | -- Certbot インストール (EPEL リポジトリ) |
|
203 | -``` |
|
204 | -# yum install python-certbot-apache |
|
205 | -``` |
|
206 | - |
|
207 | -- 証明書取得<br /> |
|
208 | -取得に成功すると「/etc/letsencrypt/live/<ドメイン1>/」に証明書が作成される。 |
|
209 | -``` |
|
210 | -# certbot --apache certonly -m <メールアドレス> -d <ドメイン1> [-d <ドメイン2> ...] --agree-tos |
|
211 | -``` |
|
212 | - |
|
213 | -- /etc/httpd/conf.d/ssl.conf (抜粋) |
|
214 | -``` |
|
215 | -Listen 443 https |
|
216 | -SSLEngine on |
|
217 | -SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem |
|
218 | -SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem |
|
219 | -SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem |
|
220 | -``` |
|
221 | - |
|
222 | -- /etc/httpd/conf.d/VirtualHosts.conf (抜粋) |
|
223 | -バーチャルホスト毎に SSL 設定が必要。 |
|
224 | -``` |
|
225 | -<VirtualHost *:80 *:443> |
|
226 | - ServerName vh1.<ドメイン1> |
|
227 | - DocumentRoot /var/www/vh1-html/ |
|
228 | - SSLEngine on |
|
229 | - SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem |
|
230 | - SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem |
|
231 | - SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem |
|
232 | - <Directory "/var/www/vh1-html"> |
|
233 | - AllowOverride All |
|
234 | - </Directory> |
|
235 | -</VirtualHost> |
|
236 | -``` |
|
237 | - |
|
238 | -- 自動更新スクリプト /etc/cron.monthly/certbot.sh |
|
239 | -```bash |
|
240 | -#!/bin/bash |
|
241 | -/bin/certbot renew |
|
242 | -``` |
|
243 | - |
|
244 | -- [Certbot](https://certbot.eff.org/) |
|
245 | -- [Webサーバー間通信内容暗号化(Apache+mod_SSL+Certbot) - CentOSで自宅サーバー構築](http://centossrv.com/apache-certbot.shtml) |
|
246 | - |
|
247 | -## Certbot 使用(ワイルドカード, 手動) |
|
248 | -- Certbot インストール (EPEL リポジトリ) |
|
249 | -``` |
|
250 | -# yum -y install yum-utils |
|
251 | -# yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional |
|
252 | -# yum install certbot-apache |
|
253 | -``` |
|
254 | - |
|
255 | -- 証明書取得(手動)<br /> |
|
256 | -途中HTTPへのテキストファイルの配置とDNSへのTXTレコードの追加を指示されるので、追加してからEnterを押して先へ進む。<br /> |
|
257 | -取得に成功すると「/etc/letsencrypt/live/<ドメイン>/」に証明書が作成される。 |
|
258 | -``` |
|
259 | -# certbot certonly --manual --server https://acme-v02.api.letsencrypt.org/directory -d "*.example.com" -d example.com |
|
260 | -``` |
|
261 | - |
|
262 | -- /etc/httpd/conf.d/ssl.conf (抜粋) |
|
263 | -``` |
|
264 | -Listen 443 https |
|
265 | -SSLEngine on |
|
266 | -SSLCertificateFile /etc/letsencrypt/live/<ドメイン>/cert.pem |
|
267 | -SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン>/privkey.pem |
|
268 | -SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン>/chain.pem |
|
269 | -``` |
|
270 | - |
|
271 | -- /etc/httpd/conf.d/VirtualHosts.conf (抜粋) |
|
272 | -バーチャルホスト毎に SSL 設定が必要。 |
|
273 | -``` |
|
274 | -<VirtualHost *:80 *:443> |
|
275 | - ServerName vh1.<ドメイン1> |
|
276 | - DocumentRoot /var/www/vh1-html/ |
|
277 | - SSLEngine on |
|
278 | - SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem |
|
279 | - SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem |
|
280 | - SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem |
|
281 | - <Directory "/var/www/vh1-html"> |
|
282 | - AllowOverride All |
|
283 | - </Directory> |
|
284 | -</VirtualHost> |
|
285 | -``` |
|
286 | - |
|
287 | -- apache 再起動 |
|
288 | -``` |
|
289 | -# systemctl restart httpd |
|
290 | -``` |
|
291 | - |
|
292 | -- 動作確認 |
|
293 | 65 | ``` |
294 | - $ openssl s_client -connect <ホスト>:443 |
|
66 | + htdigest [-c] passwdfile <realm> <username> |
|
67 | + ``` |
|
68 | + - /etc/httpd/conf.d/DigestAuth.conf |
|
69 | + ```apache |
|
70 | + <Directory "/var/www/html/Download/<realm>"> |
|
71 | + AllowOverride AuthConfig |
|
72 | + AuthType Digest |
|
73 | + AuthName "<realm>" |
|
74 | + AuthUserFile /var/www/passwd/passwords_digest |
|
75 | + Require user <username> |
|
76 | + Options None |
|
77 | + Options Indexes |
|
78 | + DirectoryIndex index.html index.htm index.php |
|
79 | + Order allow,deny |
|
80 | + Allow from all |
|
81 | + </Directory> |
|
295 | 82 | ``` |
296 | - - 設定失敗 |
|
297 | - ``` |
|
298 | - CONNECTED(00000003) |
|
299 | - 140139752064912:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:794: |
|
300 | - --- |
|
301 | - no peer certificate available |
|
302 | - --- |
|
303 | - No client certificate CA names sent |
|
304 | - --- |
|
305 | - SSL handshake has read 7 bytes and written 289 bytes |
|
306 | - --- |
|
307 | - New, (NONE), Cipher is (NONE) |
|
308 | - Secure Renegotiation IS NOT supported |
|
309 | - Compression: NONE |
|
310 | - Expansion: NONE |
|
311 | - No ALPN negotiated |
|
312 | - SSL-Session: |
|
313 | - Protocol : TLSv1.2 |
|
314 | - Cipher : 0000 |
|
315 | - Session-ID: |
|
316 | - Session-ID-ctx: |
|
317 | - Master-Key: |
|
318 | - Key-Arg : None |
|
319 | - Krb5 Principal: None |
|
320 | - PSK identity: None |
|
321 | - PSK identity hint: None |
|
322 | - Start Time: 1535884386 |
|
323 | - Timeout : 300 (sec) |
|
324 | - Verify return code: 0 (ok) |
|
325 | - --- |
|
326 | - ``` |
|
327 | - - 設定成功 |
|
328 | - ``` |
|
329 | - CONNECTED(00000003) |
|
330 | - depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3 |
|
331 | - verify return:1 |
|
332 | - depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3 |
|
333 | - verify return:1 |
|
334 | - depth=0 CN = *.<ドメイン1> |
|
335 | - verify return:1 |
|
336 | - --- |
|
337 | - Certificate chain |
|
338 | - 0 s:/CN=*.<ドメイン1> |
|
339 | - i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 |
|
340 | - 1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 |
|
341 | - i:/O=Digital Signature Trust Co./CN=DST Root CA X3 |
|
342 | - --- |
|
343 | - Server certificate |
|
344 | - -----BEGIN CERTIFICATE----- |
|
345 | - MIIGETCCBPmgAwIBAgISA3VBvI0cSyzAQGtpIaQKQRZxMA0GCSqGSIb3DQEBCwUA |
|
346 | - ... |
|
347 | - ``` |
|
348 | - |
|
349 | -- 証明書更新<br /> |
|
350 | -「--manual」で取得した場合は「renew」による自動更新ができないので、既存の証明書を削除し同名で取得し直す。 |
|
351 | -``` |
|
352 | -# certbot delete |
|
353 | -``` |
|
354 | - |
|
355 | -- 証明書の有効期限を表示<br /> |
|
356 | -getExpireDate.sh |
|
357 | -```bash |
|
358 | -#!/bin/bash |
|
359 | - |
|
360 | -CommonName=example.net |
|
361 | - |
|
362 | -NotAfter=`openssl x509 -noout -dates -in /etc/letsencrypt/live/${CommonName}/fullchain.pem | \ |
|
363 | - grep notAfter | \ |
|
364 | - sed -e "s/notAfter=//" | \ |
|
365 | - date -f - --iso-8601` |
|
366 | -echo ${NotAfter} |
|
367 | -``` |
|
368 | - |
|
369 | -## Certbot 使用(ワイルドカード, 自動) |
|
370 | -- Certbot, DNS Plugin インストール (EPEL リポジトリ) |
|
371 | -``` |
|
372 | -# yum -y install yum-utils |
|
373 | -# yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional |
|
374 | -# yum install certbot-apache python2-certbot-dns-rfc2136 |
|
375 | -``` |
|
376 | - |
|
377 | -- BIND 用認証キーの作成 |
|
378 | -Kcertbot-key.+165+43987.key, Kcertbot-key.+165+43987.private の2つのファイルが作成される。 |
|
379 | -``` |
|
380 | -# cd /etc/named/ |
|
381 | -# dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST certbot-key |
|
382 | -``` |
|
383 | - |
|
384 | -- 認証ファイル /etc/named/certbot_rfc2136.ini , ファイルモード 600 |
|
385 | -``` |
|
386 | -# Target DNS server |
|
387 | -dns_rfc2136_server = 127.0.0.1 |
|
388 | -# Target DNS port |
|
389 | -dns_rfc2136_port = 53 |
|
390 | -# TSIG key name |
|
391 | -dns_rfc2136_name = certbot-key. |
|
392 | -# TSIG key secret |
|
393 | -dns_rfc2136_secret = <Kcertbot-key.+165+43987.key のハッシュ値> |
|
394 | -# TSIG key algorithm |
|
395 | -dns_rfc2136_algorithm = HMAC-SHA512 |
|
396 | -``` |
|
397 | - |
|
398 | -- /etc/named.conf に追加 |
|
399 | -``` |
|
400 | -key "certbot-key." { |
|
401 | - algorithm hmac-sha512; |
|
402 | - secret "<Kcertbot-key.+165+43987.key のハッシュ値>"; |
|
403 | -}; |
|
404 | - |
|
405 | -view "internal" { |
|
406 | - match-clients { localhost; localnets; }; |
|
407 | - match-destinations { localhost; localnets; }; |
|
408 | - recursion yes; |
|
409 | - |
|
410 | - zone "." IN { |
|
411 | - type hint; |
|
412 | - file "named.ca"; |
|
413 | - }; |
|
414 | - |
|
415 | - include "/etc/named.rfc1912.zones"; |
|
416 | - include "/etc/named.root.key"; |
|
417 | - include "/etc/named/<ドメイン>.lan.zone"; |
|
418 | -}; |
|
419 | - |
|
420 | -view "external" { |
|
421 | - match-clients { any; }; |
|
422 | - match-destinations { any; }; |
|
423 | - recursion no; |
|
424 | - include "/etc/named/<ドメイン>.wan.zone"; |
|
425 | - include "/etc/named/_acme-challenge.<ドメイン>.wan.zone"; |
|
426 | -}; |
|
427 | -``` |
|
428 | - |
|
429 | -- /etc/named/<ドメイン>.lan.zone |
|
430 | -``` |
|
431 | -zone "<ドメイン>" { |
|
432 | - type master; |
|
433 | - file "<ドメイン>.lan.db"; |
|
434 | - update-policy { |
|
435 | - grant certbot-key. name _acme-challenge.<ドメイン>. txt; |
|
436 | - }; |
|
437 | -}; |
|
438 | -``` |
|
439 | - |
|
440 | -- /etc/named/<ドメイン>.wan.zone |
|
441 | -``` |
|
442 | -zone "<ドメイン>" { |
|
443 | - type master; |
|
444 | - file "<ドメイン>.wan.db"; |
|
445 | - allow-query { any; }; |
|
446 | - update-policy { |
|
447 | - grant certbot-key. name _acme-challenge.<ドメイン>. txt; |
|
448 | - }; |
|
449 | -}; |
|
450 | -``` |
|
451 | - |
|
452 | -- /etc/named/_acme-challenge.<ドメイン>.wan.zone |
|
453 | -``` |
|
454 | -zone "_acme-challenge.<ドメイン>" { |
|
455 | - type master; |
|
456 | - file "_acme-challenge.<ドメイン>.wan.db"; |
|
457 | - allow-query { any; }; |
|
458 | - update-policy { |
|
459 | - grant certbot-key. name _acme-challenge.<ドメイン>. txt; |
|
460 | - }; |
|
461 | -}; |
|
462 | -``` |
|
463 | - |
|
464 | -- /var/named/<ドメイン>.wan.db |
|
465 | -``` |
|
466 | -$TTL 86400 |
|
467 | -@ IN SOA ns1.<ドメイン>. root.<ドメイン>. ( |
|
468 | - 2018090500 ; Serial |
|
469 | - 28800 ; Refresh |
|
470 | - 14400 ; Retry |
|
471 | - 2592000 ; Expire |
|
472 | - 86400 ; Minimum |
|
473 | - ) |
|
474 | - IN NS ns1.<ドメイン>. |
|
475 | - IN MX 10 mail.<ドメイン>. |
|
476 | -@ IN A <グローバル IP アドレス> |
|
477 | -ns1 IN A <グローバル IP アドレス> |
|
478 | -www IN A <グローバル IP アドレス> |
|
479 | -mail IN A <グローバル IP アドレス> |
|
480 | -_acme-challenge IN NS ns1.<ドメイン>. |
|
481 | -* IN A <グローバル IP アドレス> |
|
482 | -<ドメイン>. IN TXT "v=spf1 a mx ~all" |
|
483 | -``` |
|
484 | - |
|
485 | -- /var/named/_acme-challenge.<ドメイン>.wan.db |
|
486 | -``` |
|
487 | -$TTL 86400 |
|
488 | -@ IN SOA ns1.<ドメイン>. root.<ドメイン>. ( |
|
489 | - 2018090500 ; Serial |
|
490 | - 1h ; Refresh |
|
491 | - 15m ; Retry |
|
492 | - 30d ; Expire |
|
493 | - 1h ; Minimum |
|
494 | - ) |
|
495 | - IN NS ns1.<ドメイン>. |
|
496 | -``` |
|
497 | - |
|
498 | -- `<ドメイン>.jnl: create: permission denied`(/var/named/data/named.run) 対策 |
|
499 | -``` |
|
500 | -# chmod 770 /var/named/ |
|
501 | -# setsebool -P named_write_master_zones 1 |
|
502 | -``` |
|
503 | - |
|
504 | -- 証明書取得 |
|
505 | -``` |
|
506 | -# certbot certonly \ |
|
507 | - --dns-rfc2136 \ |
|
508 | - --dns-rfc2136-credentials /etc/named/certbot_rfc2136.ini \ |
|
509 | - -d "*.<ドメイン>" -d <ドメイン> |
|
510 | -``` |
|
511 | - |
|
512 | -# mod_security |
|
513 | -## インストール |
|
514 | -- EPELリポジトリ |
|
515 | -``` |
|
516 | -# yum install mod_security mod_security_crs |
|
517 | -``` |
|
518 | - |
|
519 | -## 設定 |
|
520 | -- /etc/httpd/conf.d/mod_security.conf (抜粋) |
|
521 | -```apache |
|
522 | - # Maximum request body size we will |
|
523 | - # accept for buffering |
|
524 | - #SecRequestBodyLimit 131072 |
|
525 | - SecRequestBodyLimit 5242880 |
|
526 | - SecRequestBodyNoFilesLimit 51200 |
|
527 | -``` |
|
528 | - |
|
529 | -- /etc/httpd/modsecurity.d/modsecurity_localrules.conf |
|
530 | -```apache |
|
531 | -# Drop your local rules in here. |
|
532 | - |
|
533 | -# White List IP |
|
534 | -SecRule REMOTE_ADDR "@pmFromFile /etc/httpd/modsecurity.d/whitelist_ip.txt" \ |
|
535 | - "phase:1,id:'1000001',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off" |
|
536 | - |
|
537 | -# White List URI |
|
538 | -SecRule REQUEST_URI "@pmFromFile /etc/httpd/modsecurity.d/whitelist_uri.txt" \ |
|
539 | - "phase:1,id:'1000002',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off" |
|
540 | - |
|
541 | -# White List URI 2 |
|
542 | -SecRule REQUEST_URI "@rx ^\/Etc\/" \ |
|
543 | - "phase:1,id:'1000003',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off" |
|
544 | - |
|
545 | - # White List Sub-Domain |
|
546 | - SecRule REQUEST_HEADERS:Host "@pmFromFile /etc/httpd/modsecurity.d/whitelist_subdomain.txt" \ |
|
547 | - "phase:1,id:'1000004',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off" |
|
548 | - |
|
549 | -# ZmEu Attack / phpMyAdmin |
|
550 | -SecRule REQUEST_URI "@rx (?i)\/(php-?My-?Admin[^\/]*|mysqlmanager|myadmin|pma2005|pma\/scripts|w00tw00t[^\/]+)\/" \ |
|
551 | - "severity:alert,id:'0000013',deny,log,status:400,msg:'Unacceptable folder.',severity:'2'" |
|
552 | -``` |
|
553 | - - mod_security-2.7.1 でエラーが出るから適当にid追加したけど、idの振り方のルールってどこにあるのかな? |
|
554 | -``` |
|
555 | -ModSecurity: No action id present within the rule |
|
556 | -``` |
|
557 | - |
|
558 | -- /etc/httpd/modsecurity.d/whitelist_ip.txt<br /> |
|
559 | -mod_security による制限を行わない IP アドレスを列挙する。<br /> |
|
560 | -コメントは行頭から「#」で始める。 |
|
561 | -``` |
|
562 | -# localhost |
|
563 | -127.0.0.1 |
|
564 | - |
|
565 | -# example.com |
|
566 | -xxx.xxx.xxx.xxx |
|
567 | - |
|
568 | -# example.net |
|
569 | -yyy.yyy.yyy.yyy |
|
570 | -``` |
|
571 | - |
|
572 | -- /etc/httpd/modsecurity.d/whitelist_uri.txt<br /> |
|
573 | -mod_security による制限を行わない URI を列挙する。 |
|
574 | -``` |
|
575 | -/cgi-bin/etc/PrintEnv.cgi |
|
576 | -/cgi-bin/etc/PrintEnv_txt.cgi |
|
577 | -/cgi-bin/etc/index.cgi |
|
578 | -/cgi-bin/etc/testCGI.cgi |
|
579 | -``` |
|
580 | - |
|
581 | -- /etc/httpd/modsecurity.d/whitelist_subdomain.txt<br /> |
|
582 | -mod_security による制限を行わないホスト名を列挙する。 |
|
583 | -``` |
|
584 | -# WebApp1 |
|
585 | -vh1.takeash.net |
|
586 | -``` |
|
587 | - |
|
588 | -- /etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_20_protocol_violations.conf |
|
589 | - - id:958291 "Range: 0-", mp4 等のストリーミングや分割ダウンロードが行われるファイルのダウンロードで引っかかる。 |
|
590 | - |
|
591 | -## リンク |
|
592 | -- http://modsecurity.org/ |
|
593 | - - [Reference Manual](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual) |
|
594 | - - [The Open Web Application Security Project](https://www.owasp.org/) |
|
595 | -- [hashdos攻撃をmod_securityで防御する(CentOS+yum編) - 徳丸浩の日記](http://blog.tokumaru.org/2012/01/hashdosmodsecuritycentosyum.html) |
|
596 | -- [Attack by ZmEu - The Linux Page](http://linux.m2osw.com/zmeu-attack) phpMyAdmin 脆弱性スキャンスクリプト対策 |
|
597 | -- [黒ぶちメガネのblog » mod_securityのホワイトリスト、ブラックリストの書き方メモ](http://www.kurobuti.com/blog/?p=3775) |
|
598 | -- [禁煙できないSEの独り言: ModSecurity 2.5.12の導入](http://hiro-system.blog.ocn.ne.jp/blog/2010/04/modsecurity_251.html) |
|
599 | -- [(続)spammer対策 - ねこ様にもてあそばれる日々(2006-05-03)](http://m9841.info/?date=20060503#p02) |
|
600 | -- [mod_securityでWebサーバを守る(第1回) - ソフテック](http://www.softek.co.jp/Sec/mod_security1.html) |
|
601 | -- Webアプリケーションに潜むセキュリティホール |
|
602 | - - [Webアプリケーションファイアウォールによる防御](http://www.atmarkit.co.jp/fsecurity/rensai/webhole11/webhole01.html) |
|
603 | - - [mod_securityのXSS対策ルールを作成する](http://www.atmarkit.co.jp/fsecurity/rensai/webhole12/webhole01.html) |
|
604 | -- [UNIX的なアレ:gihyo.jp出張所](http://gihyo.jp/admin/serial/01/unix) |
|
605 | - - [第19回 知っておきたいApacheの基礎知識 その15](http://gihyo.jp/admin/serial/01/unix/0019) |
|
606 | - |
|
607 | -# mod_geoip |
|
608 | -## インストール |
|
609 | -- EPELリポジトリ |
|
610 | -``` |
|
611 | -yum install mod_geoip |
|
612 | -``` |
|
613 | - |
|
614 | -## 設定 |
|
615 | -- /etc/cron.monthly/updateGeoIP<br /> |
|
616 | -データベースの自動更新スクリプト |
|
617 | -```bash |
|
618 | -wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz |
|
619 | -gunzip GeoIP.dat.gz |
|
620 | -mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat |
|
621 | -/sbin/restorecon -v /usr/share/GeoIP/GeoIP.dat |
|
622 | -``` |
|
623 | -- GeoIP が表示されない場合は、SELinux のラベルを確認。 |
|
624 | -``` |
|
625 | -# ls -Z /usr/share/GeoIP/ |
|
626 | -Good) unconfined_u:object_r:usr_t:s0 |
|
627 | -NG) unconfined_u:object_r:admin_home_t:s0 |
|
628 | -``` |
|
629 | -ラベルが正しくない場合は下記コマンドで修正する。 |
|
630 | -``` |
|
631 | -# sealert -a /var/log/audit/audit.log |
|
632 | -# /sbin/restorecon -v /usr/share/GeoIP/GeoIP.dat |
|
633 | -``` |
|
634 | -ラベル修正後、httpd を再起動すること。 |
|
635 | -``` |
|
636 | -# service httpd restart |
|
637 | -``` |
|
638 | - |
|
639 | -## リンク |
|
640 | -- [MaxMind](http://www.maxmind.com/) |
|
641 | - - [mod_geoip2 Apache module](http://dev.maxmind.com/geoip/mod_geoip2) |
|
642 | - - [GeoLite Free Downloadable Databases](http://dev.maxmind.com/geoip/geolite) |
|
643 | -- [Apache2 mod_geoip CentOS うざい国を弾くモジュール « ORBIT SPACE](http://www.orsx.net/blog/archives/2510) |
|
644 | 83 | |
645 | 84 | # Apacheでhttp-equiv属性値を反映させる |
646 | 85 | - [META要素「http-equiv属性値とHTTPヘッダー」について考える](http://www.infoaxia.com/tools/blog/archives/cat3/) |
Linux/Apache/mod_geoip.md
... | ... | @@ -0,0 +1,38 @@ |
1 | +[[_TOC_]]
|
|
2 | +
|
|
3 | +# インストール
|
|
4 | +- EPELリポジトリ
|
|
5 | + ```
|
|
6 | + yum install mod_geoip
|
|
7 | + ```
|
|
8 | +
|
|
9 | +# 設定
|
|
10 | +- /etc/cron.monthly/updateGeoIP<br />
|
|
11 | +データベースの自動更新スクリプト
|
|
12 | + ```bash
|
|
13 | + wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
|
|
14 | + gunzip GeoIP.dat.gz
|
|
15 | + mv -f GeoIP.dat /usr/share/GeoIP/GeoIP.dat
|
|
16 | + /sbin/restorecon -v /usr/share/GeoIP/GeoIP.dat
|
|
17 | + ```
|
|
18 | +- GeoIP が表示されない場合は、SELinux のラベルを確認。
|
|
19 | + ```
|
|
20 | + # ls -Z /usr/share/GeoIP/
|
|
21 | + Good) unconfined_u:object_r:usr_t:s0
|
|
22 | + NG) unconfined_u:object_r:admin_home_t:s0
|
|
23 | + ```
|
|
24 | + - ラベルが正しくない場合は下記コマンドで修正する。
|
|
25 | + ```
|
|
26 | + # sealert -a /var/log/audit/audit.log
|
|
27 | + # /sbin/restorecon -v /usr/share/GeoIP/GeoIP.dat
|
|
28 | + ```
|
|
29 | + - ラベル修正後、httpd を再起動すること。
|
|
30 | + ```
|
|
31 | + # service httpd restart
|
|
32 | + ```
|
|
33 | +
|
|
34 | +# リンク
|
|
35 | +- [MaxMind](http://www.maxmind.com/)
|
|
36 | + - [mod_geoip2 Apache module](http://dev.maxmind.com/geoip/mod_geoip2)
|
|
37 | + - [GeoLite Free Downloadable Databases](http://dev.maxmind.com/geoip/geolite)
|
|
38 | +- [Apache2 mod_geoip CentOS うざい国を弾くモジュール « ORBIT SPACE](http://www.orsx.net/blog/archives/2510)
|
Linux/Apache/mod_security.md
... | ... | @@ -0,0 +1,95 @@ |
1 | +[[_TOC_]]
|
|
2 | +
|
|
3 | +# インストール
|
|
4 | +- EPELリポジトリ
|
|
5 | + ```
|
|
6 | + # yum install mod_security mod_security_crs
|
|
7 | + ```
|
|
8 | +
|
|
9 | +# 設定
|
|
10 | +- /etc/httpd/conf.d/mod_security.conf (抜粋)
|
|
11 | + ```apache
|
|
12 | + # Maximum request body size we will
|
|
13 | + # accept for buffering
|
|
14 | + #SecRequestBodyLimit 131072
|
|
15 | + SecRequestBodyLimit 5242880
|
|
16 | + SecRequestBodyNoFilesLimit 51200
|
|
17 | + ```
|
|
18 | +
|
|
19 | +- /etc/httpd/modsecurity.d/modsecurity_localrules.conf
|
|
20 | + ```apache
|
|
21 | + # Drop your local rules in here.
|
|
22 | +
|
|
23 | + # White List IP
|
|
24 | + SecRule REMOTE_ADDR "@pmFromFile /etc/httpd/modsecurity.d/whitelist_ip.txt" \
|
|
25 | + "phase:1,id:'1000001',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off"
|
|
26 | +
|
|
27 | + # White List URI
|
|
28 | + SecRule REQUEST_URI "@pmFromFile /etc/httpd/modsecurity.d/whitelist_uri.txt" \
|
|
29 | + "phase:1,id:'1000002',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off"
|
|
30 | +
|
|
31 | + # White List URI 2
|
|
32 | + SecRule REQUEST_URI "@rx ^\/Etc\/" \
|
|
33 | + "phase:1,id:'1000003',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off"
|
|
34 | +
|
|
35 | + # White List Sub-Domain
|
|
36 | + SecRule REQUEST_HEADERS:Host "@pmFromFile /etc/httpd/modsecurity.d/whitelist_subdomain.txt" \
|
|
37 | + "phase:1,id:'1000004',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off"
|
|
38 | +
|
|
39 | + # ZmEu Attack / phpMyAdmin
|
|
40 | + SecRule REQUEST_URI "@rx (?i)\/(php-?My-?Admin[^\/]*|mysqlmanager|myadmin|pma2005|pma\/scripts|w00tw00t[^\/]+)\/" \
|
|
41 | + "severity:alert,id:'0000013',deny,log,status:400,msg:'Unacceptable folder.',severity:'2'"
|
|
42 | + ```
|
|
43 | + - mod_security-2.7.1 でエラーが出るから適当にid追加したけど、idの振り方のルールってどこにあるのかな?
|
|
44 | + ```
|
|
45 | + ModSecurity: No action id present within the rule
|
|
46 | + ```
|
|
47 | +
|
|
48 | +- /etc/httpd/modsecurity.d/whitelist_ip.txt<br />
|
|
49 | +mod_security による制限を行わない IP アドレスを列挙する。<br />
|
|
50 | +コメントは行頭から「#」で始める。
|
|
51 | + ```
|
|
52 | + # localhost
|
|
53 | + 127.0.0.1
|
|
54 | +
|
|
55 | + # example.com
|
|
56 | + xxx.xxx.xxx.xxx
|
|
57 | +
|
|
58 | + # example.net
|
|
59 | + yyy.yyy.yyy.yyy
|
|
60 | + ```
|
|
61 | +
|
|
62 | +- /etc/httpd/modsecurity.d/whitelist_uri.txt<br />
|
|
63 | +mod_security による制限を行わない URI を列挙する。
|
|
64 | + ```
|
|
65 | + /cgi-bin/etc/PrintEnv.cgi
|
|
66 | + /cgi-bin/etc/PrintEnv_txt.cgi
|
|
67 | + /cgi-bin/etc/index.cgi
|
|
68 | + /cgi-bin/etc/testCGI.cgi
|
|
69 | + ```
|
|
70 | +
|
|
71 | +- /etc/httpd/modsecurity.d/whitelist_subdomain.txt<br />
|
|
72 | +mod_security による制限を行わないホスト名を列挙する。
|
|
73 | + ```
|
|
74 | + # WebApp1
|
|
75 | + vh1.takeash.net
|
|
76 | + ```
|
|
77 | +
|
|
78 | +- /etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_20_protocol_violations.conf
|
|
79 | + - id:958291 "Range: 0-", mp4 等のストリーミングや分割ダウンロードが行われるファイルのダウンロードで引っかかる。
|
|
80 | +
|
|
81 | +# リンク
|
|
82 | +- http://modsecurity.org/
|
|
83 | + - [Reference Manual](https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual)
|
|
84 | + - [The Open Web Application Security Project](https://www.owasp.org/)
|
|
85 | +- [hashdos攻撃をmod_securityで防御する(CentOS+yum編) - 徳丸浩の日記](http://blog.tokumaru.org/2012/01/hashdosmodsecuritycentosyum.html)
|
|
86 | +- [Attack by ZmEu - The Linux Page](http://linux.m2osw.com/zmeu-attack) phpMyAdmin 脆弱性スキャンスクリプト対策
|
|
87 | +- [黒ぶちメガネのblog » mod_securityのホワイトリスト、ブラックリストの書き方メモ](http://www.kurobuti.com/blog/?p=3775)
|
|
88 | +- [禁煙できないSEの独り言: ModSecurity 2.5.12の導入](http://hiro-system.blog.ocn.ne.jp/blog/2010/04/modsecurity_251.html)
|
|
89 | +- [(続)spammer対策 - ねこ様にもてあそばれる日々(2006-05-03)](http://m9841.info/?date=20060503#p02)
|
|
90 | +- [mod_securityでWebサーバを守る(第1回) - ソフテック](http://www.softek.co.jp/Sec/mod_security1.html)
|
|
91 | +- Webアプリケーションに潜むセキュリティホール
|
|
92 | + - [Webアプリケーションファイアウォールによる防御](http://www.atmarkit.co.jp/fsecurity/rensai/webhole11/webhole01.html)
|
|
93 | + - [mod_securityのXSS対策ルールを作成する](http://www.atmarkit.co.jp/fsecurity/rensai/webhole12/webhole01.html)
|
|
94 | +- [UNIX的なアレ:gihyo.jp出張所](http://gihyo.jp/admin/serial/01/unix)
|
|
95 | + - [第19回 知っておきたいApacheの基礎知識 その15](http://gihyo.jp/admin/serial/01/unix/0019)
|
Linux/Apache/mod_ssl.md
... | ... | @@ -0,0 +1,445 @@ |
1 | +[[_TOC_]]
|
|
2 | +
|
|
3 | +# インストール
|
|
4 | +```
|
|
5 | +# yum install mod_ssl
|
|
6 | +```
|
|
7 | +
|
|
8 | +# 自己署名証明書
|
|
9 | +
|
|
10 | +- SAN 項目を追加した設定ファイルを作成。
|
|
11 | + ```
|
|
12 | + # cd /etc/pki/tls/
|
|
13 | + # cp openssl.cnf openssl-san.cnf
|
|
14 | + ```
|
|
15 | +
|
|
16 | +- openssl.cnf と openssl-san.cnf の差分
|
|
17 | + ```
|
|
18 | + --- openssl.cnf
|
|
19 | + +++ openssl-san.cnf
|
|
20 | + @@ -104,7 +104,7 @@
|
|
21 | + ####################################################################
|
|
22 | + [ req ]
|
|
23 | + default_bits = 2048
|
|
24 | + -default_md = sha1
|
|
25 | + +default_md = sha256
|
|
26 | + default_keyfile = privkey.pem
|
|
27 | + distinguished_name = req_distinguished_name
|
|
28 | + attributes = req_attributes
|
|
29 | + @@ -222,6 +222,11 @@
|
|
30 | +
|
|
31 | + basicConstraints = CA:FALSE
|
|
32 | + keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
|
33 | + +subjectAltName=@alt_names
|
|
34 | + +
|
|
35 | + +[ alt_names ]
|
|
36 | + +DNS.1=takeash.net
|
|
37 | + +DNS.2=*.takeash.net
|
|
38 | +
|
|
39 | + [ v3_ca ]
|
|
40 | +
|
|
41 | + ```
|
|
42 | +- 証明書フォルダへ移動
|
|
43 | + ```
|
|
44 | + # cd certs/
|
|
45 | + ```
|
|
46 | +- サーバー用秘密鍵作成 (server.key)
|
|
47 | + ```
|
|
48 | + # openssl genrsa -aes128 2048 > server.key
|
|
49 | + ```
|
|
50 | +- パスフレーズ削除<br />
|
|
51 | +httpd 再起動時にパスフレーズが要求されないようにするため。
|
|
52 | + ```
|
|
53 | + # openssl rsa -in server.key -out server.key
|
|
54 | + ```
|
|
55 | +- サーバー用自己署名証明書作成 (server.crt)
|
|
56 | + ```
|
|
57 | + # openssl req -utf8 -new -key server.key -x509 -days 3650 -out server.crt -set_serial 0 \
|
|
58 | + -subj '/C=JP/ST=Tokyo/L=Chuo-ku/O=TakeAsh.net/CN=takeash.net' -extensions v3_req -config ../openssl-san.cnf
|
|
59 | + ```
|
|
60 | + - サブジェクト例 (TakeAsh.net)
|
|
61 | +
|
|
62 | + | 項目 | 用途 | サンプル |
|
|
63 | + | --- | --- | --- |
|
|
64 | + | C | 国名コード | JP |
|
|
65 | + | ST | 都道府県 | Tokyo |
|
|
66 | + | L | 区市町村 | Chuo-ku |
|
|
67 | + | O | 組織名 | TakeAsh.net |
|
|
68 | + | CN | コモンネーム(ドメイン名) | takeash.net |
|
|
69 | +
|
|
70 | + - 証明書確認<br />
|
|
71 | +「X509v3 extensions - X509v3 Subject Alternative Name」項目が存在すれば SAN が含まれている。
|
|
72 | + ```
|
|
73 | + # openssl x509 -in server.crt -text
|
|
74 | + ...
|
|
75 | + X509v3 Subject Alternative Name:
|
|
76 | + DNS:takeash.net, DNS:*.takeash.net
|
|
77 | + ...
|
|
78 | + ```
|
|
79 | +
|
|
80 | +- /etc/httpd/conf.d/ssl.conf (抜粋)
|
|
81 | + ```
|
|
82 | + SSLCertificateFile /etc/pki/tls/certs/server.crt
|
|
83 | + SSLCertificateKeyFile /etc/pki/tls/certs/server.key
|
|
84 | + DocumentRoot "/var/www/html"
|
|
85 | + SSLProtocol all -SSLv2 -SSLv3
|
|
86 | + ```
|
|
87 | +
|
|
88 | +- httpd 再起動
|
|
89 | + - CentOS 6
|
|
90 | + ```
|
|
91 | + # service httpd restart
|
|
92 | + ```
|
|
93 | + - CentOS 7
|
|
94 | + ```
|
|
95 | + # systemctl restart httpd
|
|
96 | + ```
|
|
97 | +
|
|
98 | +- 動作テスト
|
|
99 | + - https://takeash.net/cgi-bin/etc/PrintEnv.cgi
|
|
100 | + - https://www.takeash.net/cgi-bin/etc/PrintEnv.cgi
|
|
101 | +
|
|
102 | +# Certbot
|
|
103 | +- Certbot 使用前準備
|
|
104 | + - ホスト名が正引きできること。(ワイルドカード不可)
|
|
105 | + - バーチャルホストのサーバ名と要求するドメイン名のどれかが一致すること。
|
|
106 | + - インターネットから https でアクセス可能になっていること。
|
|
107 | + - https ポート解放
|
|
108 | + ```
|
|
109 | + # firewall-cmd --permanent --add-service=https
|
|
110 | + ```
|
|
111 | + - CertBot は Apache が稼働しているサーバ上で実行する。
|
|
112 | +
|
|
113 | +- Certbot インストール (EPEL リポジトリ)
|
|
114 | + ```
|
|
115 | + # yum install python-certbot-apache
|
|
116 | + ```
|
|
117 | +
|
|
118 | +- 証明書取得<br />
|
|
119 | +取得に成功すると「/etc/letsencrypt/live/<ドメイン1>/」に証明書が作成される。
|
|
120 | + ```
|
|
121 | + # certbot certonly --apache \
|
|
122 | + -m <メールアドレス> --agree-tos \
|
|
123 | + -d <ドメイン1> [-d <ドメイン2> ...]
|
|
124 | + ```
|
|
125 | +
|
|
126 | +- /etc/httpd/conf.d/ssl.conf (抜粋)
|
|
127 | + ```
|
|
128 | + Listen 443 https
|
|
129 | + SSLEngine on
|
|
130 | + SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem
|
|
131 | + SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem
|
|
132 | + SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem
|
|
133 | + ```
|
|
134 | +
|
|
135 | +- /etc/httpd/conf.d/VirtualHosts.conf (抜粋)
|
|
136 | +バーチャルホスト毎に SSL 設定が必要。
|
|
137 | + ```
|
|
138 | + <VirtualHost *:80 *:443>
|
|
139 | + ServerName vh1.<ドメイン1>
|
|
140 | + DocumentRoot /var/www/vh1-html/
|
|
141 | + SSLEngine on
|
|
142 | + SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem
|
|
143 | + SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem
|
|
144 | + SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem
|
|
145 | + <Directory "/var/www/vh1-html">
|
|
146 | + AllowOverride All
|
|
147 | + </Directory>
|
|
148 | + </VirtualHost>
|
|
149 | + ```
|
|
150 | +
|
|
151 | +- 自動更新スクリプト /etc/cron.monthly/certbot.sh
|
|
152 | + ```bash
|
|
153 | + #!/bin/bash
|
|
154 | + /bin/certbot renew
|
|
155 | + ```
|
|
156 | +
|
|
157 | +# Certbot (ワイルドカード, 手動)
|
|
158 | +- Certbot インストール (EPEL リポジトリ)
|
|
159 | + ```
|
|
160 | + # yum -y install yum-utils
|
|
161 | + # yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
|
|
162 | + # yum install certbot-apache
|
|
163 | + ```
|
|
164 | +
|
|
165 | +- 証明書取得(手動)<br />
|
|
166 | +途中HTTPへのテキストファイルの配置とDNSへのTXTレコードの追加を指示されるので、追加してからEnterを押して先へ進む。<br />
|
|
167 | +取得に成功すると「/etc/letsencrypt/live/<ドメイン>/」に証明書が作成される。
|
|
168 | + ```
|
|
169 | + # certbot certonly --manual \
|
|
170 | + --server https://acme-v02.api.letsencrypt.org/directory \
|
|
171 | + -d "*.example.com" -d example.com
|
|
172 | + ```
|
|
173 | +
|
|
174 | +- /etc/httpd/conf.d/ssl.conf (抜粋)
|
|
175 | + ```
|
|
176 | + Listen 443 https
|
|
177 | + SSLEngine on
|
|
178 | + SSLCertificateFile /etc/letsencrypt/live/<ドメイン>/cert.pem
|
|
179 | + SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン>/privkey.pem
|
|
180 | + SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン>/chain.pem
|
|
181 | + ```
|
|
182 | +
|
|
183 | +- /etc/httpd/conf.d/VirtualHosts.conf (抜粋)
|
|
184 | +バーチャルホスト毎に SSL 設定が必要。
|
|
185 | + ```
|
|
186 | + <VirtualHost *:80 *:443>
|
|
187 | + ServerName vh1.<ドメイン1>
|
|
188 | + DocumentRoot /var/www/vh1-html/
|
|
189 | + SSLEngine on
|
|
190 | + SSLCertificateFile /etc/letsencrypt/live/<ドメイン1>/cert.pem
|
|
191 | + SSLCertificateKeyFile /etc/letsencrypt/live/<ドメイン1>/privkey.pem
|
|
192 | + SSLCertificateChainFile /etc/letsencrypt/live/<ドメイン1>/chain.pem
|
|
193 | + <Directory "/var/www/vh1-html">
|
|
194 | + AllowOverride All
|
|
195 | + </Directory>
|
|
196 | + </VirtualHost>
|
|
197 | + ```
|
|
198 | +
|
|
199 | +- apache 再起動
|
|
200 | +CentOS 7
|
|
201 | + ```
|
|
202 | + # systemctl restart httpd
|
|
203 | + ```
|
|
204 | +
|
|
205 | +- 証明書更新<br />
|
|
206 | +「--manual」で取得した場合は「renew」による自動更新ができないので、既存の証明書を削除し同名で取得し直す。
|
|
207 | + ```
|
|
208 | + # certbot delete
|
|
209 | + ```
|
|
210 | +
|
|
211 | +# Certbot (ワイルドカード, 自動)
|
|
212 | +- Certbot, DNS Plugin インストール (EPEL リポジトリ)
|
|
213 | + ```
|
|
214 | + # yum -y install yum-utils
|
|
215 | + # yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
|
|
216 | + # yum install certbot-apache python2-certbot-dns-rfc2136
|
|
217 | + ```
|
|
218 | +
|
|
219 | +- BIND 用認証キーの作成
|
|
220 | +Kcertbot-key.+165+43987.key, Kcertbot-key.+165+43987.private の2つのファイルが作成される。
|
|
221 | + ```
|
|
222 | + # cd /etc/named/
|
|
223 | + # dnssec-keygen -a HMAC-SHA512 -b 512 -n HOST certbot-key
|
|
224 | + ```
|
|
225 | +
|
|
226 | +- 認証ファイル /etc/named/certbot_rfc2136.ini , ファイルモード 600
|
|
227 | + ```
|
|
228 | + # Target DNS server
|
|
229 | + dns_rfc2136_server = 127.0.0.1
|
|
230 | + # Target DNS port
|
|
231 | + dns_rfc2136_port = 53
|
|
232 | + # TSIG key name
|
|
233 | + dns_rfc2136_name = certbot-key.
|
|
234 | + # TSIG key secret
|
|
235 | + dns_rfc2136_secret = <Kcertbot-key.+165+43987.key のハッシュ値>
|
|
236 | + # TSIG key algorithm
|
|
237 | + dns_rfc2136_algorithm = HMAC-SHA512
|
|
238 | + ```
|
|
239 | +
|
|
240 | +- /etc/named.conf に追加
|
|
241 | + ```
|
|
242 | + key "certbot-key." {
|
|
243 | + algorithm hmac-sha512;
|
|
244 | + secret "<Kcertbot-key.+165+43987.key のハッシュ値>";
|
|
245 | + };
|
|
246 | +
|
|
247 | + view "internal" {
|
|
248 | + match-clients { localhost; localnets; };
|
|
249 | + match-destinations { localhost; localnets; };
|
|
250 | + recursion yes;
|
|
251 | +
|
|
252 | + zone "." IN {
|
|
253 | + type hint;
|
|
254 | + file "named.ca";
|
|
255 | + };
|
|
256 | +
|
|
257 | + include "/etc/named.rfc1912.zones";
|
|
258 | + include "/etc/named.root.key";
|
|
259 | + include "/etc/named/<ドメイン>.lan.zone";
|
|
260 | + };
|
|
261 | +
|
|
262 | + view "external" {
|
|
263 | + match-clients { any; };
|
|
264 | + match-destinations { any; };
|
|
265 | + recursion no;
|
|
266 | + include "/etc/named/<ドメイン>.wan.zone";
|
|
267 | + include "/etc/named/_acme-challenge.<ドメイン>.wan.zone";
|
|
268 | + };
|
|
269 | + ```
|
|
270 | +
|
|
271 | +- /etc/named/<ドメイン>.lan.zone
|
|
272 | + ```
|
|
273 | + zone "<ドメイン>" {
|
|
274 | + type master;
|
|
275 | + file "<ドメイン>.lan.db";
|
|
276 | + update-policy {
|
|
277 | + grant certbot-key. name _acme-challenge.<ドメイン>. txt;
|
|
278 | + };
|
|
279 | + };
|
|
280 | + ```
|
|
281 | +
|
|
282 | +- /etc/named/<ドメイン>.wan.zone
|
|
283 | + ```
|
|
284 | + zone "<ドメイン>" {
|
|
285 | + type master;
|
|
286 | + file "<ドメイン>.wan.db";
|
|
287 | + allow-query { any; };
|
|
288 | + update-policy {
|
|
289 | + grant certbot-key. name _acme-challenge.<ドメイン>. txt;
|
|
290 | + };
|
|
291 | + };
|
|
292 | + ```
|
|
293 | +
|
|
294 | +- /etc/named/_acme-challenge.<ドメイン>.wan.zone
|
|
295 | + ```
|
|
296 | + zone "_acme-challenge.<ドメイン>" {
|
|
297 | + type master;
|
|
298 | + file "_acme-challenge.<ドメイン>.wan.db";
|
|
299 | + allow-query { any; };
|
|
300 | + update-policy {
|
|
301 | + grant certbot-key. name _acme-challenge.<ドメイン>. txt;
|
|
302 | + };
|
|
303 | + };
|
|
304 | + ```
|
|
305 | +
|
|
306 | +- /var/named/<ドメイン>.wan.db
|
|
307 | + ```
|
|
308 | + $TTL 86400
|
|
309 | + @ IN SOA ns1.<ドメイン>. root.<ドメイン>. (
|
|
310 | + 2018090500 ; Serial
|
|
311 | + 28800 ; Refresh
|
|
312 | + 14400 ; Retry
|
|
313 | + 2592000 ; Expire
|
|
314 | + 86400 ; Minimum
|
|
315 | + )
|
|
316 | + IN NS ns1.<ドメイン>.
|
|
317 | + IN MX 10 mail.<ドメイン>.
|
|
318 | + @ IN A <グローバル IP アドレス>
|
|
319 | + ns1 IN A <グローバル IP アドレス>
|
|
320 | + www IN A <グローバル IP アドレス>
|
|
321 | + mail IN A <グローバル IP アドレス>
|
|
322 | + _acme-challenge IN NS ns1.<ドメイン>.
|
|
323 | + * IN A <グローバル IP アドレス>
|
|
324 | + <ドメイン>. IN TXT "v=spf1 a mx ~all"
|
|
325 | + ```
|
|
326 | +
|
|
327 | +- /var/named/_acme-challenge.<ドメイン>.wan.db
|
|
328 | + ```
|
|
329 | + $TTL 86400
|
|
330 | + @ IN SOA ns1.<ドメイン>. root.<ドメイン>. (
|
|
331 | + 2018090500 ; Serial
|
|
332 | + 1h ; Refresh
|
|
333 | + 15m ; Retry
|
|
334 | + 30d ; Expire
|
|
335 | + 1h ; Minimum
|
|
336 | + )
|
|
337 | + IN NS ns1.<ドメイン>.
|
|
338 | + ```
|
|
339 | +
|
|
340 | +- `<ドメイン>.jnl: create: permission denied`(/var/named/data/named.run) 対策
|
|
341 | + ```
|
|
342 | + # chmod 770 /var/named/
|
|
343 | + # setsebool -P named_write_master_zones 1
|
|
344 | + ```
|
|
345 | +
|
|
346 | +- 証明書取得
|
|
347 | + ```
|
|
348 | + # certbot certonly \
|
|
349 | + --dns-rfc2136 \
|
|
350 | + --dns-rfc2136-credentials /etc/named/certbot_rfc2136.ini \
|
|
351 | + -d "*.<ドメイン>" -d <ドメイン>
|
|
352 | + ```
|
|
353 | +
|
|
354 | +# 動作確認
|
|
355 | +
|
|
356 | +## 証明書の内容をテキスト出力
|
|
357 | +```
|
|
358 | +# openssl x509 -text -in /etc/letsencrypt/live/<ドメイン>/cert.pem
|
|
359 | +```
|
|
360 | +
|
|
361 | +## 証明書の有効期限を表示
|
|
362 | +getExpireDate.sh
|
|
363 | +```bash
|
|
364 | +#!/bin/bash
|
|
365 | +
|
|
366 | +CommonName=example.net
|
|
367 | +
|
|
368 | +NotAfter=`openssl x509 -noout -dates -in /etc/letsencrypt/live/${CommonName}/fullchain.pem | \
|
|
369 | + grep notAfter | \
|
|
370 | + sed -e "s/notAfter=//" | \
|
|
371 | + date -f - --iso-8601`
|
|
372 | +echo ${NotAfter}
|
|
373 | +```
|
|
374 | +
|
|
375 | +## SSL 接続確認
|
|
376 | +```
|
|
377 | +$ openssl s_client -connect <ホスト>:443
|
|
378 | +```
|
|
379 | +### 設定失敗
|
|
380 | +```
|
|
381 | +CONNECTED(00000003)
|
|
382 | +140139752064912:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:794:
|
|
383 | +---
|
|
384 | +no peer certificate available
|
|
385 | +---
|
|
386 | +No client certificate CA names sent
|
|
387 | +---
|
|
388 | +SSL handshake has read 7 bytes and written 289 bytes
|
|
389 | +---
|
|
390 | +New, (NONE), Cipher is (NONE)
|
|
391 | +Secure Renegotiation IS NOT supported
|
|
392 | +Compression: NONE
|
|
393 | +Expansion: NONE
|
|
394 | +No ALPN negotiated
|
|
395 | +SSL-Session:
|
|
396 | + Protocol : TLSv1.2
|
|
397 | + Cipher : 0000
|
|
398 | + Session-ID:
|
|
399 | + Session-ID-ctx:
|
|
400 | + Master-Key:
|
|
401 | + Key-Arg : None
|
|
402 | + Krb5 Principal: None
|
|
403 | + PSK identity: None
|
|
404 | + PSK identity hint: None
|
|
405 | + Start Time: 1535884386
|
|
406 | + Timeout : 300 (sec)
|
|
407 | + Verify return code: 0 (ok)
|
|
408 | +---
|
|
409 | +```
|
|
410 | +### 設定成功
|
|
411 | +```
|
|
412 | +CONNECTED(00000003)
|
|
413 | +depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
|
|
414 | +verify return:1
|
|
415 | +depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
|
|
416 | +verify return:1
|
|
417 | +depth=0 CN = *.<ドメイン1>
|
|
418 | +verify return:1
|
|
419 | +---
|
|
420 | +Certificate chain
|
|
421 | + 0 s:/CN=*.<ドメイン1>
|
|
422 | + i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
|
|
423 | + 1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
|
|
424 | + i:/O=Digital Signature Trust Co./CN=DST Root CA X3
|
|
425 | +---
|
|
426 | +Server certificate
|
|
427 | +-----BEGIN CERTIFICATE-----
|
|
428 | +MIIGETCCBPmgAwIBAgISA3VBvI0cSyzAQGtpIaQKQRZxMA0GCSqGSIb3DQEBCwUA
|
|
429 | +...
|
|
430 | +```
|
|
431 | +
|
|
432 | +# リンク
|
|
433 | +- [Let's Encrypt](https://letsencrypt.org/) Free SSL/TLS Certificates
|
|
434 | + - [Certbot](https://certbot.eff.org/) / [DNS Plugins](https://certbot.eff.org/docs/using.html#dns-plugins) / [certbot-dns-rfc2136](https://certbot-dns-rfc2136.readthedocs.io/en/latest/)
|
|
435 | +
|
|
436 | +- [Webサーバー間通信内容暗号化(Apache+mod_SSL+Certbot) - CentOSで自宅サーバー構築](http://centossrv.com/apache-certbot.shtml)
|
|
437 | +- [CertbotとBINDの組み合わせでLet's Encryptのワイルドカード証明書を取得・更新する](https://qiita.com/yasuhirokimura/items/3a95e169f806b3772e06)
|
|
438 | +- [OpenSSL CSR with Alternative Names one-line - End Point Blog](http://blog.endpoint.com/2014/10/openssl-csr-with-alternative-names-one.html)
|
|
439 | +- [SAN対応 x.509 証明書を取得するためのCSRを作成する - Qiita](http://qiita.com/saitara/items/eda74ac6a950122b5f31)
|
|
440 | +- [subjectAltNameでバーチャルホスト - Kung Noi Blog](http://www.goodnai.com/blog/2010/05/07/subjectaltname%E3%81%A7%E3%83%90%E3%83%BC%E3%83%81%E3%83%A3%E3%83%AB%E3%83%9B%E3%82%B9%E3%83%88/)
|
|
441 | +- [Webサーバー間通信内容暗号化(Apache+mod_SSL) - CentOSで自宅サーバー構築](http://centossrv.com/apache-ssl.shtml)
|
|
442 | +- [SSL Server Test (Powered by Qualys SSL Labs)](https://www.ssllabs.com/ssltest/)
|
|
443 | +- [ssl certificate - how to add subject alernative name to ssl certs? - Stack Overflow](https://stackoverflow.com/questions/%38%37%34%34%36%30%37)
|
|
444 | + - keytool -certreq -ext SAN=dns:example.com,ip:192.168.0.1
|
|
445 | + - [keytool(ja)](https://docs.oracle.com/javase/jp/8/docs/technotes/tools/windows/keytool.html) / [keytool(en)](http://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html)
|
Linux/_Sidebar.md
... | ... | @@ -1,6 +1,6 @@ |
1 | 1 | # [[Linux|/Linux/Home]]
|
2 | +- [[Apache|/Linux/Apache/Home]]
|
|
2 | 3 | - [[Install|/Linux/Install/Home]]
|
3 | -- [[Apache]]
|
|
4 | 4 | - [[Customize]]
|
5 | 5 | - [[Gollum]]
|
6 | 6 | - [[HardwareInfo]]
|