Why do I get the issue «nginx: [emerg] "index" directive is not allowed here in /etc/nginx/nginx.conf:30»?

Hi,

I’m currently running Magento CE 2.1.2 on my Linux webserver but when using the provided “nginx.conf.example” file, I get two errors while starting the nginx instance.


– Unit nginx.service has begun starting up.
Oct 30 14:04:10 LeVence systemd[1]: Failed to reset devices.list on /system.slice/nginx.service: No such file or directory
Oct 30 14:04:10 LeVence nginx[20931]: nginx: [emerg] “index” directive is not allowed here in /etc/nginx/nginx.conf:30
Oct 30 14:04:10 LeVence nginx[20931]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 30 14:04:10 LeVence systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 30 14:04:10 LeVence systemd[1]: Failed to start A high performance web server and a reverse proxy server.


Nginx “nginx.conf” file: http://pastebin.com/Utf3Lgkx
Nginx “default” file: http://pastebin.com/Xjiwq5zh

Nginx version: v1.6.2
PHP5 version: v5.6.24-0+deb8u1 (cli) (built: Jul 26 2016 08:17:07)

Thanks.

Sincerely,

  • Chris

An index directive should be used in a http, server, or location context: https://nginx.org/en/docs/http/ngx_http_index_module.html#index

The index directive in the nginx.conf.sample file is outside of a http, server, or location context:

It is because the nginx.conf.sample file is supposed to be included in a proper context.

Thanks!