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

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

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

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Q&A

1回答

1652閲覧

nginxの設定のスコープ

kxphotographer

総合スコア37

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

0グッド

0クリップ

投稿2016/05/09 08:43

お世話になっております。

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.comsubdomain.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}

のような感じで、プログラミング言語のスコープのように設定値を一定範囲に閉じ込めたいのですが、これを実現出来る書き方はあるのでしょうか。

よろしくお願い致します。

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

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

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

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

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

guest

回答1

0

共通箇所を別ファイルにして include する方法はダメでしょうか。
1つのファイルで実現する方法は思いつきませんでした。

投稿2016/05/09 11:27

TaichiYanagiya

総合スコア12141

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問