1.报错具体信息
nginx: [emerg] invalid number of arguments in “location” directive in /usr/local/nginx/conf/nginx.conf:47
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
2.报错背景
在完成源码安装LNMP架构完成的情况下,对nginx服务进行优化,在设置缓存时间的配置时。修改过配置文件后,检测配置文件时报错。
具体报错信息如下:
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost html]# nginx -t
nginx: [emerg] invalid number of arguments in "location" directive in /usr/local
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
3.排错分析过程
这个问题比较简单,看报错信息可以判断,问题出在配置文件的47行,应该就是配置时有错误,进入配置文件查看47行内容并且查错。
[root@localhost html]# vim /usr/local/nginx/conf/nginx.conf
可以发现47行配置的是识别图片的格式,以多个格式结尾的图片,格式和$要连起来不能有空格,才表示以什么结尾。所以有空格是错误的。
4.解决方法
去掉配置文件中多余的空格应该就可以解决了。
5.验证
[root@localhost html]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful