お世話になっております。
HTTPサーバとしてnginxを使用しています。最近、Let's encryptを使用してSSL証明書を設定しました。
しかし現状、サブドメインごとに全く同じ設定内容を書いています。
lang
1server { 2 server_name example.com; 3 listen 443 ssl http2; 4 5 ssl_certificate /path/to/example.com/cert.pem; 6 ssl_certificate /path/to/example.com/key.pem; 7 8 root /path/to/example.com/webroot; 9 index index.html index.htm; 10 location / { 11 try_files $uri $uri/ =404; 12 } 13} 14server { 15 server_name subdomain.example.com; 16 listen 443 ssl http2; 17 18 ssl_certificate /path/to/example.com/cert.pem; 19 ssl_certificate /path/to/example.com/key.pem; 20 21 root /path/to/subdomain.example.com/webroot; 22 index index.html index.htm; 23 location / { 24 try_files $uri $uri/ =404; 25 } 26}
sslの設定項目はexample.com
とsubdomain.example.com
で全く同じなので、設定項目の記述を1箇所にまとめたいのです。
しかし、例えば
lang
1ssl_certificate /path/to/example.com/cert.pem; 2ssl_certificate /path/to/example.com/key.pem; 3 4server { 5 server_name example.com; 6 listen 443 ssl http2; 7 8 root /path/to/example.com/webroot; 9 index index.html index.htm; 10 location / { 11 try_files $uri $uri/ =404; 12 } 13} 14server { 15 server_name subdomain.example.com; 16 listen 443 ssl http2; 17 18 root /path/to/subdomain.example.com/webroot; 19 index index.html index.htm; 20 location / { 21 try_files $uri $uri/ =404; 22 } 23}
と書いた場合、この後に読み込まれた別の設定ファイルにsslの設定がない場合、この値が適用されてしまい意図しない設定となってしまいます。
イメージですが、
lang
1setting_scope { 2 ssl_certificate /path/to/example.com/cert.pem; 3 ssl_certificate /path/to/example.com/key.pem; 4 5 server { 6 server_name example.com; 7 listen 443 ssl http2; 8 9 root /path/to/example.com/webroot; 10 index index.html index.htm; 11 location / { 12 try_files $uri $uri/ =404; 13 } 14 } 15 server { 16 server_name subdomain.example.com; 17 listen 443 ssl http2; 18 19 root /path/to/subdomain.example.com/webroot; 20 index index.html index.htm; 21 location / { 22 try_files $uri $uri/ =404; 23 } 24 } 25}
のような感じで、プログラミング言語のスコープのように設定値を一定範囲に閉じ込めたいのですが、これを実現出来る書き方はあるのでしょうか。
よろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。