set no-cache for specific URL in nginx

5,635 views
Skip to first unread message

Avinash Bijja

unread,
Dec 7, 2012, 4:26:22 AM12/7/12
to openre...@googlegroups.com
Hey Guys,
I am new to this group and this is my first post.

Issue: I use Amazon's CDN CloudFront to serve pages but have an issue with a URL, so i just want to tell cloudfront to dont cache a particular page/url.
I want to set no-cache in header for a particular URL using headers-more-module.

Can some body help me to achieve this?
Any kind of help is appreciated.

Thankyou.
Avinash.

agentzh

unread,
Dec 7, 2012, 1:57:45 PM12/7/12
to openre...@googlegroups.com
Hello!

On Fri, Dec 7, 2012 at 1:26 AM, Avinash Bijja wrote:
> I am new to this group and this is my first post.
>

Welcome!

> Issue: I use Amazon's CDN CloudFront to serve pages but have an issue with a
> URL, so i just want to tell cloudfront to dont cache a particular page/url.
> I want to set no-cache in header for a particular URL using
> headers-more-module.
>

You're encouraged to use ngx_lua instead of ngx_headers_more for this:

location ... {
...

header_filter_by_lua '
if ngx.var.uri == "/foo" then
ngx.header["Cache-Control"] = "no-cache"
end
';
}

Because it is Lua, you can do arbitrarily complicated test against URL
(or any other things) here :)

Best regards,
-agentzh

Avinash Bijja

unread,
Dec 8, 2012, 6:44:03 AM12/8/12
to openre...@googlegroups.com
Hi,

Thanks for your kind reply.

I have added the below lines in my vhosts.conf using headers-more-module

location /my/url {
more_set_headers 'Cache-Control: no-cache';
}
But this throws error 404 at me for that url.

Requirement: I want to tell cloudfront to proxy a request to specific url to the origin server.

Thanks!

Avinash.



--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group, send email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



agentzh

unread,
Dec 8, 2012, 3:22:26 PM12/8/12
to openre...@googlegroups.com
Hello!

On Sat, Dec 8, 2012 at 3:44 AM, Avinash Bijja wrote:
> I have added the below lines in my vhosts.conf using headers-more-module
>
> location /my/url {
> more_set_headers 'Cache-Control: no-cache';
> }
> But this throws error 404 at me for that url.
>
> Requirement: I want to tell cloudfront to proxy a request to specific url to
> the origin server.
>

Then just add a proxy_pass directive to your location /my/url.

You only configure an output filter in that location. There's no
meaningful content handler defined there, so Nginx just maps the URI
to your file system and looks for the file my/url under your document
root directory.

You can find the Nginx tutorials here to prevent such basic mistakes:

http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-enuk.html

Best regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages