[英]Caching is not working in nginx using proxy_cache.
我正在嘗試在我的openresty nginx Web服務器中設置基本緩存。 我從許多不同的教程中嘗試了milion的不同組合,但是我做不到。 這是我的nginx.conf文件
user www-data;
worker_processes 4;
pid /run/openresty.pid;
worker_rlimit_nofile 30000;
events {
worker_connections 20000;
}
http {
proxy_cache_path /tmp/nginx/cache levels=1:2 keys_zone=cache:10m max_size=100m inactive=60m;
proxy_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
include mime.types;
default_type application/octet-stream;
access_log /var/log/openresty/access.log;
error_log /var/log/openresty/error.log;
include ../sites/*;
lua_package_cpath '/usr/local/lib/lua/5.1/?.so;;';
}
這是我的服務器配置
server {
# Listen on port 8080.
listen 8080;
listen [::]:8080;
# The document root.
root /var/www/cache;
# Add index.php if you are using PHP.
index index.php index.html index.htm;
# The server name, which isn't relevant in this case, because we only have one.
server_name cache.com;
# Redirect server error pages to the static page /50x.html.
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/cache;
}
location /test.html {
root /var/www/cache;
default_type text/plain;
try_files $uri /$uri;
expires 1h;
add_header Cache-Control "public";
proxy_cache cache;
proxy_cache_valid 200 301 302 60m;
}
}
緩存應該可以正常工作,error.log或access.log中沒有任何內容,緩存系統文件夾為空,當我從curl(curl -I)獲取標頭時,甚至沒有顯示帶有$ upstream_cache_status的X-Cache標頭。 現在在我的nginx(openresty)配置中,沒有--with-ngx_http_proxy_module標志,因此模塊在那里。 我不知道我在做什么錯,請幫忙。
您沒有定義任何可以緩存的內容:proxy_cache與proxy_pass
proxy_cache
工作。
在http
塊內定義的add_header
將覆蓋server
塊中定義的add_header
。 這是有關add_header
的文檔片段
可能有幾個add_header指令。 當且僅當當前級別上沒有定義add_header指令時,這些指令才從上一級繼承 。
如果指定了always參數(1.7.5),則無論響應代碼如何,都將添加標頭字段。
因此,您將無法看到X-Cache標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.