我有以下 niginx 配置文件:
server {
listen 80;
server_name pajilleros.com www.pajilleros.com;
access_log off;
location / {
root /home/website/public_html;
index /silex/web/index.php;
try_files $uri $uri/ /rewrite.php?$args;
}
# Rewrite to another folder
location /themes {
rewrite ^/themes/(.*) /silex/web/themes/$1;
}
#Rewrite of page
location /some-page {
try_files $uri $uri/ /silex/web/index.php;
}
location /another-page {
try_files $uri $uri/ /silex/web/index.php;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /home/website/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_connect_timeout 5s;
fastcgi_send_timeout 120s;
fastcgi_read_timeout 120s;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
reset_timedout_connection on;
}
}
我想将页面 /some-page 和 /another-page 作为静态缓存 30 秒,但我只知道如何使用 proxy_pass 进行缓存,在这种情况下,我没有使用 proxy_pass,只使用 php-fpm。
我可以用 nginx 来做吗?还是必须使用 varnish 作为缓存?
谢谢 !
答案1
是的,你可以用 Nginx 来实现。使用 FastCGI 缓存。以下是众多教程之一,教你如何实现:
https://www.digitalocean.com/community/tutorials/how-to-setup-fastcgi-caching-with-nginx-on-your-vps