Nginx未知指令" set"

时间:2015-09-09 08:15:32

标签: nginx

我遇到nginx配置问题。当我运行nginx conftest时,我收到错误消息nginx: [emerg] unknown directive "    set"

nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-http_image_filter_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=-Wl,-rpath,/usr/lib64 --add-module=/home/rpmbuild/rpmbuild/SOURCES/MODULES/lua-nginx-module --add-module=/home/rpmbuild/rpmbuild/SOURCES/MODULES/ngx_devel_kit --add-module=/home/rpmbuild/rpmbuild/SOURCES/MODULES/echo-nginx-module --add-module=/home/rpmbuild/rpmbuild/SOURCES/MODULES/set-misc-nginx-module --add-module=/home/rpmbuild/rpmbuild/SOURCES/MODULES/nginx-module-vts

这是我的图像重新调整大小的位置,设置$ ok会导致问题。

#images
location ~* ^/restapi/rest/\d+/images/ {
    set $ok "no";
 
    # request parsing
    # possible values:
    #   <without query parameters>
    #   h32, h64, h96, h128, h192, h256, h320, h384, h512, h720, h1080
    #   w32, w64, w96, w128, w192, w256, w320, w384, w512, w720, w1920
    if ($args ~ ^((w|h)(32|64|96|128|192|256|320|384|512|720)|w1920|h1080)?$) {
        set $ok "yes";
    }
 
    if ($ok = "no") {
        return 404;
    }
 
    proxy_pass http://resizer;
    proxy_cache_methods GET;
    proxy_cache mycache;
    proxy_cache_valid 200 302 15m;
    proxy_cache_key $uri$is_args$args;
    proxy_cache_lock on;
    proxy_cache_lock_timeout 30s;
    proxy_cache_use_stale updating;
}

有人可以告诉我我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

nginx: [emerg] unknown directive " set"

Part withing quotes is exactly what nginx tries to use as a directive name. It obviously has some characters that shouldn't be there. Most common mistake is to copy text from some web page that tends to use non-breakable spaces for indentation.

Remove that spaces from config and put normal ones instead.