Nginx 启动提示 [emerg] 配置中没有 "events" 部分

在 X-WAF 部署中,您需要创建一个新的 nginx 配置文件。但是,在测试 nginx 配置时,发现了一个错误,无法启动 nginx。

我参考了 http://blog.51cto.com/14071176/2318054 的教程,一步一步按照文章中的配置操作,但是我遇到了一个问题。

root@VM-0-6-ubuntu:~# /usr/local/openresty/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] no "events" section in configuration
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed

root@VM-0-6-ubuntu:~# /usr/local/openresty/nginx/sbin/nginx
nginx: [emerg] no "events" section in configuration

通常情况下,执行 /usr/local/openresty/nginx/sbin/nginx -t 会有两个成功的输出,但我的输出是一个成功和一个失败。

点赞
用户274500
用户274500

http { 行上面添加 events { } :

events {}
http {
    server {
        # 在这里添加你的代码
    }
}
2019-06-17 12:36:56
用户2793677
用户2793677
上方添加 http{}

events { worker_connections 1024; }

```

Nginx worker_connections:设置工作进程可以同时打开的最大连接数。

2021-08-07 17:47:51