Nginx 启动提示 [emerg] 配置中没有“事件”部分

Posted

技术标签:

【中文标题】Nginx 启动提示 [emerg] 配置中没有“事件”部分【英文标题】:Nginx startup prompt [emerg] no "events" section in configuration 【发布时间】:2019-06-26 03:27:45 【问题描述】:

在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 会成功两次,而我的是成功和失败。

【问题讨论】:

只需在http 行上方添加events 谢谢,我使用另一个网站的 nginx.conf 配置文件来解决这个问题。确实是nginx.conf的问题。我指的另一个站点是kongdewei.cn/2017/08/11/… 【参考方案1】:

只需在http 行上方添加events

events 
http 
    server 
        # Your code here
    

【讨论】:

你知道这是做什么的吗? @BenBieler 它是连接处理指令的部分。例如worker_connections 768; nginx.org/en/docs/ngx_core_module.html#events【参考方案2】:

放在http上面

events 
    worker_connections 1024;

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

【讨论】:

以上是关于Nginx 启动提示 [emerg] 配置中没有“事件”部分的主要内容,如果未能解决你的问题,请参考以下文章

nginx启动提示nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx 服务器 有一个 虚拟挂不上去 启动是下面的提示

nginx 启动报错 nginx: [emerg] getgrnam("root") failed

nginx无法启动的问题。

解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

LNMP环境搭建之Nginx服务启动失败