Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Enable UWSGI caching only when Cache-Control headers are set

I'd like to use Nginx to cache a Uwsgi app. The app sets the Cache-Control header for some requests. The Nginx-cache should only be enabled for those requests and respect the max-age condition.

So I'm trying to set uwsgi_no_cache 1 for requests where upstream doesn't set Cache-Control. And uwsgi_no_cache 0 for requests where upstream does set the Cache-Control header.

However, this does not work:

set $no_cache 1;
if ($sent_http_cache_control) {
    set $no_cache 0;
}
uwsgi_no_cache $no_cache;

The problem lies with $sent_http_cache_control, unfortunately it does not reflect the header set upstream.

Is there a way of only enabling caching in Nginx when Cache-Control is set upstream?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For headers returned by the upstream service you will need to use the $upstream_http_ prefix

https://nginx.org/en/docs/http/ngx_http_upstream_module.html#var_upstream_http_

So in your case it should be $upstream_http_cache_control

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!