
Eu tenho o Nginx instalado como um proxy front-end para o Apache, onde o Apache atende PHP e o Nginx atende arquivos estáticos. Estou tendo problemas ao configurar o Nginx para armazenar em cache a saída do PHP em um arquivo estático. Tentei com proxy_cache, mas obviamente estou fazendo algo errado.
Aqui está minha configuração básica:
server {
listen 80;
root /var/www/web;
index index.php index.html index.htm;
server_name web.com;
location / {
try_files $uri $uri/ /index.php;
}
# cache static files
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
access_log off;
add_header Cache-Control public;
}
location ~ \.php$ {
proxy_pass http://127.0.0.1:8080;
# Set header to be what we requested
proxy_set_header Host $host;
# Set proxy_cache expiry time
proxy_cache_valid 200 302 5m;
proxy_cache_valid 404 1m;
proxy_cache_valid 301 1h;
# Need this for snooping with tcpdump (turns off upstream compression)
proxy_set_header Accept-Encoding "";
# Set real IP header (needed for client IP detection in apache)
proxy_set_header X-Real-IP $remote_addr;
# Explicitly allow critical headers
proxy_pass_header Set-Cookie;
# Prevent 304 responses being returned from Apache and cached by nginx
proxy_set_header If-None-Match "";
}
location ~ /\.ht {
deny all;
}
}
Responder1
definirproxy_cache_pathno seu http{} - contexto e defina sua zona e parâmetros
http {
...
proxy_cache_path /tmp/cache/blue blue:100m ...;
proxy_cache_path /tmp/cache/white white:100m ...;
...
}
definirproxy_cachezone/off no contexto de servidor/localização correspondente e suas opções também
por exemplo, defina seus caminhos de cache globalmente e ative/desative para cada servidor/local
location /blue {
proxy_cache blue;
proxy_cache_...
}
location /white {
proxy_cache white;
proxy_cache_...
}
location /red {
proxy_cache off;
proxy_cache_...
}
cuidado, seus arquivos em cache estarão em formato binário