我想用 NGINX 設定 nuxt 作為負載均衡器。此外,我想為影像添加一些快取。
現在我使用這個得到 404 的影像:
location ~ ^/img. \.(?:ico|gif|jpe?g|webp|png|woff2?|eot|otf|ttf|svg|js|css)$ {
expires 365d;
add_header Pragma public;
add_header Cache-Control "public";
try_files $uri $uri/ @proxy;
}
location @proxy {
expires 365d;
add_header Content-Security-Policy "default-src 'self' 'unsafe-inline';";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Cache-Status $upstream_cache_status;
proxy_redirect off;
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_ignore_headers Cache-Control;
proxy_http_version 1.1;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://1649681_app/$request_uri;
#proxy_cache nuxt-cache;
#proxy_cache_bypass $arg_nocache; # probably better to change this
#proxy_cache_valid 200 302 60m; # set this to your needs
#proxy_cache_valid 404 1m; # set this to your needs
#proxy_cache_lock on;
#proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
#proxy_cache_key $uri$is_args$args;
}
這條線似乎$request_uri是錯誤的proxy_pass http://1649681_app/$request_uri- 但我怎樣才能將請求的路徑傳遞給@proxy-location?
uj5u.com熱心網友回復:
proxy_pass不,在命名(以及正則運算式)位置內使用指令變數指定 URI 并不是完全錯誤的。然而這樣的事情會有一個缺點——如果你不能使用 IP 而不是主機名來指定你的上游地址,你需要resolver在你的配置中定義一個(更糟)或一個額外的upstream塊來定義你的1649681_app后端(更好)。可以在此處找到更多詳細資訊(完全相同也適用于命名位置)。
話雖如此,您如何看待,proxy_pass如果您不明確指定任何請求 URI 將傳遞到指令中指定的上游?它將正是正在處理的 URI(如果由于某種原因您需要傳遞修改后的 URI,則需要通過rewrite規則對其進行修改)。
對于給定的配置,假設您不需要修改請求 URI 或查詢引數,您應該簡單地使用
proxy_pass http://1649681_app;
而且,您了解$uri/引數的確切含義嗎?它使try_files指令檢查給定的 URI 是否是在其中搜索索引檔案的目錄。我真的懷疑您是否需要使用這種正則運算式模式。洗掉它,它只是一個額外的(某種昂貴的)系統內核stat呼叫。采用
try_files $uri @proxy;
反而。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/480559.html
