Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
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 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda