Nginx startup prompt [emerg] no "events" section in configuration
Asked Answered
P

2

139

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.

Pneumatic answered 1/2, 2019 at 14:22 Comment(2)
Just add events { } above the http { line.Twister
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 kongdewei.cn/2017/08/11/…Pneumatic
B
236

Just add events { } above the http { line:

events {}
http {
    server {
        # Your code here
    }
}
Bakst answered 17/6, 2019 at 12:36 Comment(3)
Do you know what this does?Cynthia
@BenBieler it is the section for connection processing directives. For example, worker_connections 768; nginx.org/en/docs/ngx_core_module.html#eventsPyrrolidine
It doesn't do anything, actually, unless you put something inside of it. Weird that an empty events {} solves the startup check.Witty
T
28

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.

Thwack answered 7/8, 2021 at 17:47 Comment(1)
It must work yes, but what if you just want to keep the default value ? Then defining an empty events {} section is better IMO.Rugged

© 2022 - 2024 — McMap. All rights reserved.