“location“ directive is not allowed here in /usr/local/nginx/conf.d/vhost_1.conf:10

问题描述
在配置nginx的配置文件server模块的时候报如下错误:
*"location" directive is not allowed here in /usr/local/nginx/conf.d/vhost_1.conf:10*
下图是我的配置文件,乍一看没有问题
其实这些我们另外添加的模块要放在http或者server模块下才能使用
在这里插入图片描述
修改解决
在这里插入图片描述
用nginx -t来测试一下语法,发现就没有问题了
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx配置文件中,出现nginx: [emerg] "location" directive is not allowed here的错误,原因是在配置文件的某个位置不允许使用"location"指令。根据引用中的错误信息,我们可以看到该错误出现在"/usr/local/nginx/conf/nginx.conf"文件的第78行。 要解决这个问题,可以参考引用的建议,将需要修改的代码添加到原nginx.conf文件的最后一个"}"之前,并重新启动Nginx。 具体操作步骤如下: 1. 打开"/usr/local/nginx/conf/nginx.conf"文件。 2. 找到第78行,检查该位置是否允许使用"location"指令。根据错误信息,该位置不允许使用"location"指令。 3. 将需要修改的代码添加到配置文件的最后一个"}"之前的合适位置。 4. 保存文件并关闭。 5. 重新启动Nginx,使修改生效。 通过以上步骤,您应该能够解决nginx: [emerg] "location" directive is not allowed here的错误。请注意,在修改配置文件之前,最好备份原始文件以防止意外情况的发生。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Nginx 问题 之 nginx: [emerg] unknown directive "echo" in /weblogic/nginx/conf/nginx.conf:43-附件资源](https://download.csdn.net/download/weixin_42197841/15583854)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [nginx: [emerg] “server“ directive is not allowed here in /usr/local/nginx/conf/nginx.conf:2](https://blog.csdn.net/FYBINge/article/details/122100207)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决:nginx: [emerg] “upstream“ directive is not allowed here in /usr/local/nginx/conf/nginx.conf:...](https://blog.csdn.net/A755967073/article/details/127942761)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值