nginx: [emerg] “location“ directive is not allowed here

时间:2025-03-18 21:01:25

nginx配置出错。

D:\nginx>nginx.exe -t
nginx: [emerg] "location" directive is not allowed here in D:\nginx/conf/www_boss/zencart1.5.conf:1
nginx: configuration file D:\nginx/conf/nginx.conf test failed

这是因为我在中有这样的语句:

include www_boss/*.conf;

结果把 D:\nginx/conf/www_boss/zencart1. 当作站点包含进来了。

D:\nginx/conf/www_boss/zencart1. 的内容:

location / {
	 index   ;
           
	if (!-e $request_filename)
	{
	   #....
	}
}

解决办法:把zencart1.放到 D:\nginx/conf/inc/zencart1. 中,在site中include它。

 include inc/zencart1.;