nginx: [emerg] “location“ directive is not allowed here in etcnginxdefault.dphp.conf:7
作者:mmseoamin日期:2024-01-19

在nginx反代理实验中,修改nginx的配置文件后,执行nginx -t发现了以下错误。

nginx: [emerg] “location“ directive is not allowed here in etcnginxdefault.dphp.conf:7,第1张

这个错误是由于在nginx配置文件中的某个位置使用了不允许使用的指令“location”。根据提供的引用内容,可以看出在两个不同的配置文件中都出现了这个错误。解决这个问题的方法是找到这个指令所在的位置并将其移动到正确的位置。具体来说,可以按照以下步骤进行操作:

  1. 打开配置文件 /etc/nginx/default.d/php.conf 或者 D:\nginx/conf/www_boss/zencart1.5.conf,找到第7行或者第1行。
  2. 确认该行是否包含“location”指令,如果是,则需要将其移动到正确的位置。
  3. 根据nginx的语法规则,location指令只能在server块或者location块中使用。因此,如果该指令出现在其他位置,就会导致错误。
  4. 确认该指令所在的上下文环境,将其移动到正确的位置。例如,如果该指令应该在server块中使用,则将其移动到server块中。
  5. 保存文件并重新加载nginx配置文件,以确保更改生效。

针对本实验,我在php.conf文件中,将location以下的所有内容注释掉。问题成功解决!

nginx: [emerg] “location“ directive is not allowed here in etcnginxdefault.dphp.conf:7,第2张

nginx: [emerg] “location“ directive is not allowed here in etcnginxdefault.dphp.conf:7,第3张