我正在尝试在我的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;
}
}
当我从curl(curl -I)获取标头时,缓存应该可以正常工作,error.log或access.log中没有任何内容,缓存系统文件夹为空,甚至没有显示带有$ upstream_cache_status的X-Cache标头。现在在我的nginx(openresty)配置中,没有--with-ngx_http_proxy_module标志,因此模块在那里。我不知道我在做什么错,请帮忙。