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

213
Views
Nginx Cache request blocked by CORS policy when Origin is down

My cache is working fine as long as the Origin Server is running. I use "proxy_cache_use_stale" as seen below. Tried it with different Error Codes and with Updating but it won't show the cached files (They are in the cache folder). I also tried the various CORS solutions that I found but that doesn't work either.

My .conf file:

proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=300d use_temp_path=off;

server {

    listen 80;
    listen [::]:80;

    location / {

    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' "$http_origin" always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        add_header 'Access-Control-Allow-Headers' "Origin, X-Requested-With, Content-Type, Accept" always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
     }

        proxy_cache my_cache;

        proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504 http_403 http_404 http_429;
        proxy_cache_background_update on;
        proxy_cache_lock on;

        proxy_cache_key $host$request_uri|$request_body;
        proxy_cache_valid 200 302 301 800d;
        proxy_ignore_headers Cache-Control;
        proxy_cache_methods GET HEAD POST;

        proxy_pass example.com;
        add_header X-Cache-Status $upstream_cache_status;
   }
}

Error:

Access to XMLHttpRequest at 'http://example.com' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Problem solved. There was no problem with the CORS, the problem was in the json.

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!