fastcgi_cache для nginx

neoks
На сайте с 17.03.2010
Offline
152
1397

Не могу настроить fastcgi_cache для nginx, хочу сайт который обновляется раз в сутки (без комантов и т.д) поставить на fastcgi_cache, но как это сделать не могу понять.

Связка: nginx 1.* + php-fpn

nginx.conf

user  nginx;

worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on


include /etc/nginx/conf.d/*.conf;
}


server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.php;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {

root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

куда и что прописать что-бы включить кеширование всех страниц ? не зависимо от того авторизован или нет и т.д

pupseg
На сайте с 14.05.2010
Offline
364
#1
neoks:
Не могу настроить fastcgi_cache для nginx, хочу сайт который обновляется раз в сутки (без комантов и т.д) поставить на fastcgi_cache, но как это сделать не могу понять.

Связка: nginx 1.* + php-fpn

nginx.conf
user  nginx;

worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;



events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
fastcgi_cache_path /tmp/nginx levels=1:1 keys_zone=pagecache:32m max_size=2048m inactive=1d;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on


include /etc/nginx/conf.d/*.conf;
}






server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.php;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {

root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache pagecache;
fastcgi_cache_key "$request_method|$is_args|$host|$request_uri";
fastcgi_hide_header "Set-Cookie";
fastcgi_ignore_headers "Cache-Control" "Expires";
fastcgi_cache_valid 200 301 302 304 10m;
fastcgi_cache_min_uses 1;


}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}



куда и что прописать что-бы включить кеширование всех страниц ? не зависимо от того авторизован или нет и т.д

типо как то так

Качественная помощь в обслуживании серверов. (/ru/forum/661100) Бесплатных консультаций не даю, не помогаю, не обучаю. Минималка от 100$. Как пропатчить KDE-просьба не спрашивать. Есть форумы (http://linux.org.ru) и полезные сайты (http://www.opennet.ru/).
neoks
На сайте с 17.03.2010
Offline
152
#2

Спасибо работает :)

pupseg
На сайте с 14.05.2010
Offline
364
#3

ну вы папку /tmp/nginx только создайте

neoks
На сайте с 17.03.2010
Offline
152
#4
pupseg:
ну вы папку /tmp/nginx только создайте

Создал, уже и проверил :)

ab -n 1000 -c 500 http://IP/index.php

вчера мучал весь день:

 # Настройки кеширования

fastcgi_temp_path /tmp/nginx 1 2; # Каталог для хранение временных файлов
fastcgi_cache adw0rd; # Имя зоны кеша
fastcgi_cache_key "$request_method|$host|$request_uri"; # Из этих данных строится хеш
fastcgi_hide_header "Set-Cookie"; # Не передавать клиенту заголовки кук
fastcgi_cache_min_uses 1; # Кол-во запросов, после которых ответ будет закеширован
fastcgi_cache_valid 10m; # Время жизни кеша
fastcgi_cache_use_stale error timeout invalid_header http_500; # Случаи при которых будет использоватся старый кеш

работало через раз и то очень не понятно, решил уже тут запостить, сэкономил нервы и можно теперь дальше ерундой заниматься :)

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий