nginx检查报错:nginx: [emerg] "server" directive is not allowed here in

想检查一个配置文件是否正确,-c 指定之后发现有报错,如下:

[root@op-2:~# nginx -t -c /etc/nginx/conf.d/default.conf
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/default.conf:1
nginx: configuration file /etc/nginx/conf.d/default.conf test failed

 

有时候文件是正确无误,但是也会报错。

实际问题是进行语法检测的对象有问题;

要检测现有的修改过的Nginx配置是否有错误,不是只检测 .conf文件,而是不管任何时候,始终都是去检测主文件/etc/nginx/nginx.conf,只有这样,才能顺利的在对应的模块加载.conf 文件。

这样保证了配置的前后语境的正确性,这样才是真正的检测。

所以正确的检测修改的Nginx的语法是否错误的命令应该是: nginx -t -c /etc/nginx/nginx.conf ,如果配置文件有异常,会直接报出,否则就是

[root@op-2:~# nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


[root@op-2:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

转载于:https://www.cnblogs.com/orzs/p/11563875.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
报错提示的意思是在nginx.conf配置文件的第53行出现了一个错误,错误是"server"指令在这里不被允许使用。这个错误导致了nginx的配置文件测试失败。\[1\] 这个错误通常是由于配置文件中的语法错误或者指令放置位置不正确引起的。要解决这个问题,可以按照以下步骤进行排查: 1. 首先,检查nginx.conf配置文件的第53行,确保"server"指令的使用位置正确。通常,"server"指令应该在http块内部使用,而不是在全局配置块中使用。 2. 检查配置文件中的其他语法错误。可能会有其他的指令或者语法错误导致了这个错误。可以使用nginx -t命令来测试配置文件的语法是否正确,如果有其他错误,会一并显示出来。\[2\] 3. 如果以上步骤都没有解决问题,可以尝试使用备份的配置文件或者重新安装nginx来解决。有时候,配置文件可能被损坏或者不完整,重新安装nginx可以解决这个问题。\[3\] 总结起来,当出现"nginx: \[emerg\] 'server' directive is not allowed here"的错误时,需要检查配置文件中的语法错误和指令位置是否正确,并可以尝试使用备份的配置文件或者重新安装nginx来解决问题。 #### 引用[.reference_title] - *1* *2* *3* [nginx: [emerg] “serverdirective is not allowed here in /usr/local/nginx/conf/nginx.conf53](https://blog.csdn.net/guguai7/article/details/118145007)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值