現象
Nginx起動時に重複している設定がないのに次のように怒られてNginxが立ち上がらない場合があります。
-- Unit nginx.service has begun starting up. Mar 25 00:26:37 hoge nginx[1742]: nginx: [emerg] "proxy_buffer_size" directive is duplicate in /etc/nginx/conf.d/rproxy.conf:9 Mar 25 00:26:37 hoge nginx[1742]: nginx: configuration file /etc/nginx/nginx.conf test failed Mar 25 00:26:37 hoge systemd[1]: nginx.service: Control process exited, code=exited status=1 Mar 25 00:26:37 hoge systemd[1]: nginx.service: Failed with result 'exit-code'. Mar 25 00:26:37 hoge systemd[1]: Failed to start A high performance web server and a reverse proxy server. -- Subject: Unit nginx.service has failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support
Grepで重複した設定項目があるか確認しても、重複が見当たりません・・・。
# grep -R "proxy_buffer_size" /etc/nginx/* ./conf.d/rproxy.conf:proxy_buffer_size 1m;
原因と対応
includeが重複していることでこのような問題が起こる場合があります。
以下の例の場合、include /etc/nginx/conf.d/*.conf;
が重複しています。
2行記載されているinclude設定のうち、1つを削除することで本問題は解決します。
## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; include /etc/nginx/conf.d/*.conf;