126

In the X-WAF deployment, you need to create a new nginx configuration file. However, when testing the nginx configuration, an error is found and nginx cannot be started.

I refer to http://blog.51cto.com/14071176/2318054,I did it step by step according to the configuration in the article, but I had a problem.

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

Under normal circumstances, executing /usr/local/openresty/nginx/sbin/nginx -t will have two successes, but mine is a success and a failure.

neuro
  • 14,948
  • 3
  • 36
  • 59
Dora
  • 1,261
  • 2
  • 6
  • 3
  • 35
    Just add `events { }` above the `http {` line. – Richard Smith Feb 01 '19 at 14:46
  • Thanks, I used the nginx.conf configuration file in another website to fix this problem. It is indeed a problem in nginx.conf.The other site I refer to is http://kongdewei.cn/2017/08/11/%E7%9C%8B%E6%88%91%E5%A6%82%E4%BD%95%E6%90%AD%E5%BB%BA%E4%B8%80%E6%AC%BE%E6%96%B9%E4%BE%BF%E6%98%93%E7%94%A8%E7%9A%84%E4%BA%91WAF/ – Dora Feb 02 '19 at 06:07

2 Answers2

220

Just add events { } above the http { line:

events {}
http {
    server {
        # Your code here
    }
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176
  • 53
    Do you know what this does? – Ben Bieler Aug 11 '20 at 09:20
  • 4
    @BenBieler it is the section for connection processing directives. For example, worker_connections 768; http://nginx.org/en/docs/ngx_core_module.html#events – Almenon Mar 12 '21 at 00:38
  • It doesn't do anything, actually, unless you put something inside of it. Weird that an empty `events {}` solves the startup check. – Josh M. Apr 22 '23 at 02:47
23

Put above http{}

events {
    worker_connections 1024;
}

Nginx worker_connections : sets the maximum number of simultaneous connections that can be opened by a worker process.

Dylan B
  • 796
  • 8
  • 16
  • 3
    It must work yes, but what if you just want to keep the default value ? Then defining an empty `events {}` section is better IMO. – lbris Apr 30 '22 at 07:18