事象
Linux環境にてNGINXのコンフィグチェックを行うと以下のようなエラーとなる。
# nginx -t [emerg] no "ssl_certificate" is defined for the "ssl" directive in /etc/nginx/nginx.conf:34
環境情報
# nginx -v nginx version: nginx/1.20.2
原因/解決策
以下の設定項目の前方に「;」が入っていなかった。
... ssl_certificate "/etc/nginx/cert.crt"; ssl_certificate_key "/etc/nginx/cert.key";
セミコロンを付与した状態で再度テストをすると
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
正常にチェックが通る。
以下、補足です。
補足
nginxが読み込む設定ファイルにエラーがあると以下のように起動に失敗します。
# systemctl restart nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
ステータスを見ると以下のように起動時に失敗しているのconfigファイルを見に行くと
Process: 40406 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE) Main PID: 39746 (code=exited, status=0/SUCCESS)
冒頭のエラーとなっていました。
directive...という部分に文法誤りがない場合は、その前方にて;のつけ忘れがないかを確認してみてください。
以上です。