想检查一个配置文件是否正确,-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

nginx检查报错:nginx: [emerg] "server" directive is not allowed here in的更多相关文章

  1. 阿里云centOS7.4 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/vhost/xxxxxx.conf:2

    里云centOS7.4配置多个站点遇到的问题nginx: [emerg] "server" directive is not allowed here in /etc/nginx/ ...

  2. 重启虚拟机后,再次重启nginx会报错:[emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

    问题: 重启虚拟机后,再次重启nginx会报错: open() "/var/run/nginx/nginx.pid" failed (2: No such file or dire ...

  3. nginx检查报错 error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory

    在centos7.3上编译安装nginx-1.12.2 启动测试出错 [root@web02 local]# /usr/local/nginx/sbin/nginx -t /usr/local/ngi ...

  4. nginx启动报错nginx: [error] open() "/usr/local/etc/nginx/logs/nginx.pid" failed

    问题:nginx启动的时候会报丢失pid的错误 nginx: [error] open() “/usr/local/var/run/nginx.pid” failed 解决方案: sudo nginx ...

  5. Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"

    Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"     出现如图所示错误,处理办法如下 去nginx解压目录下执行 ./co ...

  6. nginx启动报错

    nginx启动的时候报错 nginx: [emerg] invalid number of arguments in "root" directive in /etc/nginx/ ...

  7. Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案

    Win7下nginx默认80端口被System占用,造成nginx启动报错的解决方案   在win7 32位旗舰版下,启动1.0.8版本nginx,显示如下错误:  [plain] 2012/04/0 ...

  8. nginx报错 nginx: [alert] kill(25903, 1) failed (3: No such process)

    当nginx 中报错 时 nginx报错 nginx: [alert] kill(25903, 1) failed (3: No such process) 通过在nginx/sbin,目录下 运行命 ...

  9. Nginx启动报错:10013: An attempt was made to access a socket in a way forbidden

    Nginx在win7,win2008下启动报错:bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket i ...

随机推荐

  1. 曹工说Spring Boot源码(5)-- 怎么从properties文件读取bean

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  2. c# 模拟post登录

    使用模拟登录大致可以分为两步 一.post登录获取cookis public CookieContainer GetCookie(string url,string account,string pa ...

  3. 搭建docker+k8s踩过的坑

    问题一: # yum install -y etcd kubernetes Error: docker-ce-cli conflicts with :docker--.gitb2f74b2.el7.c ...

  4. ARM伪指令和协处理器访问指令

    伪指令本身没有对应的机器码 .global声明全局符号,点事GUN汇编的特点 .data定义数据段 .equ DA #0x89 定义宏 .align 4 4字节对齐 mov 指令里的立即数只能是8位的 ...

  5. 牛客假日团队赛5 K 金币馅饼 (DP 基础题)

    链接:https://ac.nowcoder.com/acm/contest/984/K 来源:牛客网 金币馅饼 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  6. BZOJ - 2243 染色 (LCT链修改+链查询)

    同样是可以用LCT解决的树剖问题之一. 注意反转的时候要考虑对左右端点颜色的影响,而且要先反转再打标记(这点不知道为啥) #include<bits/stdc++.h> using nam ...

  7. python连接 MySQ 数据库

    python 是目前比较流行的语言,所以学习一下 首先需要 安装MySQL-python驱动 下载地址:http://dev.mysql.com/downloads/connector/python/ ...

  8. mybatis简单用法

    1.resultType 和 resultMap 引言: MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表 ...

  9. JAVA笔记28-正则表达式(补充、不重要)

    一.Greedy(贪婪的)尽可能多的匹配,Reluctant(不情愿的)尽可能少的匹配.Possessive(独占的)不常用. Greedy 数量词 X? X,一次或一次也没有 X* X,零次或多次 ...

  10. 【leetcode】689. Maximum Sum of 3 Non-Overlapping Subarrays

    题目如下: In a given array nums of positive integers, find three non-overlapping subarrays with maximum ...