When do we need to use http block in nginx config file?

Viewed 11869

I am reading nginx beginner's tutorial, on the section Serving Static Content they have

http {
  server {
  }
}

but when I add an http block I get the error

[emerg] "http" directive is not allowed here …

When I remove the http block and change the conf file to this, it works fine:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/example.com/html;
    index index.html index.htm;

    # make site accessible from http://localhost/
    server_name localhost

    location / {
      try_files $uri $uri/ /index.html;
  }

I suspect that I am missing something simple, but why do they use http to serve static files?

1 Answers
Related