Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:47:53+00:00 2026-06-09T18:47:53+00:00

When using nginx fastcgi_cache, I cache HTTP 200 responses longer than I do any

  • 0

When using nginx fastcgi_cache, I cache HTTP 200 responses longer than I do any other HTTP code. I want to be able to conditionally set the expires header based on this code.

For example:

fastcgi_cache_valid   200 302  5m;
fastcgi_cache_valid   any      1m;

if( $HTTP_CODE = 200 ) {
  expires 5m;
}
else {
  expires 1m;
}

Is something like the above possible (inside a location container)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:47:54+00:00Added an answer on June 9, 2026 at 6:47 pm

    sure, from http://wiki.nginx.org/HttpCoreModule#Variables

    $sent_http_HEADER
    
    The value of the HTTP response header HEADER when converted to lowercase and 
    with 'dashes' converted to 'underscores', e.g. $sent_http_cache_control, 
    $sent_http_content_type...; 
    

    so you could match on $sent_http_response in an if-statement

    there’s a gotcha though since http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires doesn’t list if’s as allowed context for the expires directive

    you can work around that setting a variable in the if-block, and then referring to it later like so:

    set $expires_time 1m;
    if ($send_http_response ~* "200") {
      set $expires_time 5m; 
    }
    expires $expires_time;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Nginx, and I want to rewrite all url with the following
I'm using nginx and its map module ( http://wiki.nginx.org/HttpMapModule ) to create rewrites depending
How can I redirect mydomain.example and any subdomain *.mydomain.example to www.adifferentdomain.example using Nginx?
I am trying to using Nginx to redirect from /t/latest/2 to /topics/latest/page/2 rewrite ^/t/latest$
i started using nginx upload module (which creates upload files like /tmp/000121545) but i
I am using nginx + unicorn in linode. This is my nginx.conf upstream unicorn
Is is possible to do the following using nginx rewrite: Convert a url from
I use supervisord for managing tornado with no issuse wnhile using nginx as a
I have an image that is served as static file using Nginx, but I
I'm using django with nginx and gunicorn. nginx is supposed to serve the static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.