Problem with 403 in response to curl on server and locally but it works after adding no-cache...

Discussão em 'Angular' iniciado por Wierzba, Março 30, 2025.

  1. Wierzba

    Wierzba Guest

    I have a problem with my server and locally from my computer. When I try to make a curl query to my server (using Nginx), I get a 403 Forbidden response. However, if I add the Cache-Control header: no-cache, no-store, must-revalidate and Pragma: no-cache, the query works fine and gets a 200 response.

    This is config Nginx for my api.


    server {
    server_name api.mydomain.pl;
    listen 443 ssl;


    ssl_certificate /etc/letsencrypt/live/api.mydomain.pl/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.mydomain.pl/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;


    location /api/ {


    if ($request_method = 'OPTIONS') {
    add_header 'Access-Control-Allow-Origin' 'https://mydomain.pl' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Cache-Control, Pragma' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Max-Age' 3600 always;
    return 204;
    }

    add_header 'Access-Control-Allow-Origin' 'https://mydomain.pl' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, Cache-Control, Pragma' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Expose-Headers' 'Authorization' always;

    add_header 'Cache-Control' 'no-cache, no-store, must-revalidate' always;
    add_header 'Pragma' 'no-cache' always;
    add_header 'Expires' '0' always;

    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    }

    access_log /var/log/nginx/api.access.log;
    error_log /var/log/nginx/api.error.log;
    }

    Continue reading...

Compartilhe esta Página