Opened 10 years ago

Closed 10 years ago

#602 closed defect (invalid)

fastcgi_cache doesn't accept variable

Reported by: Javier Garcia Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.6.x
Keywords: fastcgi_cache, variable Cc: javiertury@…
uname -a: Linux localhost.localdomain 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.6.0
TLS SNI support enabled
configure arguments: --prefix=/usr/share/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-debug --add-module=/builddir/build/BUILD/nginx-1.6.0/modsecurity-2.8.0/nginx/modsecurity --add-module=/builddir/build/BUILD/nginx-1.6.0/ngx_cache_purge-2.1 --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,-E

Description

I use nginx provided by atomic repos in centos 6.5

First I set up the following variable in the server block.
set $fastcgi_cache_zone one;

BTW I tried to define a global/default one in the http block but I get this error:
[emerg] "set" directive is not allowed here in /etc/nginx/nginx.conf

Then I write this in the php location block which is inside the server block
fastcgi_cache $fastcgi_cache_zone;

And this also fails in the purge location block which is inside the server block. However this is using the module ngx_cache_purge-2.1 which I don't know if it is supported here.
fastcgi_cache_purge $fastcgi_cache_zone "$scheme$request_method$host$1";

The error is this one for both:
nginx: [emerg] "fastcgi_cache" zone "$fastcgi_cache_zone" is unknown in /etc/nginx/nginx.conf:53

Change History (2)

comment:1 by Javier Garcia, 10 years ago

Also trying to pass a variable as an argument for fastcgi_pass doesn't work. It doesn't give any errors when executing "nginx -t" but from the logs I can tell it can't read the variables as nginx thinks it is empty:

*1 no host in upstream "", client: 127.0.0.1

comment:2 by Maxim Dounin, 10 years ago

Resolution: invalid
Status: newclosed

The fastcgi_cache directive doesn't support variables. If variables can be used in a certain directive arguments, that's explicitly documented. See, e.g., fastcgi_param documentation - "The value can contain text, variables, and their combination."

The set directive can't be used in http context. Note "context" in the documentation.

The fastcgi_pass directive support variables (though it's implies special processing, and may require resolver to be defined, see http://nginx.org/r/proxy_pass; the fastcgi_pass documentation needs to be updated to include these details). If it doesn't work for you - you are probably doing something wrong, consider writing to the mailing list if you need help.

Note: See TracTickets for help on using tickets.