【发布时间】:2017-07-28 18:18:49
【问题描述】:
在我的 Nginx 服务器上,为了节省时间,我制作了 etc/nginx/include.conf 并将这一行放在 etc/nginx/sites-available/site1.conf 中:
location / {
include /etc/nginx/include.conf;
try_files $uri $uri/ /index.php?page=$uri;
}
include.conf 的内容:
if ($http_referer ~* (badreferers)) {
return 403;
}
在测试conf文件的时候,出现这个错误: [emerg] /etc/nginx/include.conf:1 中的未知指令“if”
当我将if语句直接放在etc/nginx/sites-available/site1.conf中时,它不会报错。
这里有什么问题?
更新:
nginx -V 给:
nginx版本:由gcc 4.8.4(Ubuntu)构建的nginx/1.4.6(Ubuntu) 4.8.4-2ubuntu1~14.04.3) 启用 TLS SNI 支持的配置参数:--with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror= format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc /nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var /lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var /lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp- path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with -http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_mod ule --with-mail --with-mail_ssl_module
【问题讨论】:
-
它可能对空格敏感,因此请尝试删除多余的空格。
if ($http_referer ~* ...) -
嗨,感谢您的建议,测试时不会改变问题。
-
@C.A.Vuyk 你检查了stackoverflow.com/questions/19165976/… 这个线程的坏字符解决方案吗?
-
是的,为了确定,我什至重新输入了整个声明
-
@C.A.Vuyk 你是自己编译 nginx,还是来自 OS 发行版/repo 或其他一些现成的编译源?请更新您的问题并包含
nginx -V的输出。
标签: nginx http-referer nginx-location