nginx – Why Some Nginx Configs Are Missing the HTTP Block?

nginx

According to the nginx beginner's guide:

Serving Static Content

An important web server task is serving out
files (such as images or static HTML pages). You will implement an
example where, depending on the request, files will be served from
different local directories: /data/www (which may contain HTML files)
and /data/images (containing images). This will require editing of the
configuration file and setting up of a server block inside the http
block with two location blocks.

But most of the nginx conf files are missing this http { ... } part.

I can't find anything on the document describing about it.

Is this http { ... } block just optional? When should I use/omit it?

Best Answer

http {} block is essential for serving HTTP and is mandatory for it. The thing is, it's defined in the main nginx.conf configuration file, not in the includes. So includes only define a server {} block, at least one for each vhost, and they are actually included inside the http {} block in the main config file.