nginx の設定ファイルテスト (dry-run) で "http" directive is not allowed と出たとき

nginx の設定ファイルのテスト (dry-run)

これです。

$ sudo nginx -t

結論

/etc/nginx/sites-enabled/ 配下などのところに設定ファイルを置いていませんか。

すなわち、nginx.confinclude しているファイルを読み込んだときに以下のようなエラーが発生していませんか。

nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/foobar.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed

そして、その設定ファイルの最上位のディレクティブが http となっていませんか。

修正方法

最上位ディレクティブの httpを削除します。

理由

include 配下の設定ファイルはすでに http ディレクティブ配下にあるので、二重に http ディレクティブを書いていることになるからです。

したがって削除すれば OK です。

参考

Powered by はてなブログ