簡體   English   中英

緩存預檢 Nginx Laravel JWT

[英]Cache Preflights Nginx Laravel JWT

我正在使用 Laravel JWT 令牌,應用程序在不同的域 URL(例如 app.site.com 和 api.site.com)上有 UI 和 API,我想避免或緩存預檢(僅用於第一個請求,因為它會增加響應時間),我添加了標題 Access-Control-Max-Age 但由於某種原因,它不起作用。

這是 Nginx 配置

server {
listen 81;
  listen [::]:81;
    
      server_name loc.localhost.com;
    
      root /home/user/projects/app/public;
      index index.php;
      charset utf-8;
      
    
      location / {
        
        try_files $uri $uri/ /index.php?$query_string;
      }
    
      location ~ \.php$ {
       
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        proxy_connect_timeout 3600; 
        proxy_send_timeout 3600; 
        proxy_read_timeout 3600; 
        send_timeout 3600;
    
        if ($request_method = OPTIONS) {
    
          add_header Content-Length 0;
          add_header Content-Type text/html;
          add_header Access-Control-Max-Age 1728000;
          add_header Cache-Control "public";
          expires 2d;
        }
    
      }
    }

每個請求的預檢請求的屏幕截圖。 預檢

我還修改了 Laravel,所以所有 API 請求都發送到同一個端點,因為我已經看到它將每個 URL 視為單獨的緩存,所以所有 API 請求都是這樣發送的。

https://api.site.com/api/?action=/auth/login
https://api.site.com/api/?action=/items
https://api.site.com/api/?action=/categories

編輯:我已將令牌移動到標題中。

任何相關幫助將不勝感激,以避免多次預檢。

如果不對應用程序的建模方式進行重大更改,就無法避免這種情況。 這是因為每個請求都是不同的。 嘗試使用它,也許它會幫助您改變應用程序的運行方式並減少請求時間減少預檢時間

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM