大网数据广告活动
服务器运维问答

Why some nginx configs are missing the http block?

· 52CE 我爱测

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…

问题原文

原帖链接 · AGamePlayer · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · drookie · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-01-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。