Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
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 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda