
Apache가 PHP를 서비스하고 Nginx가 정적 파일을 서비스하는 Apache의 프런트 엔드 프록시로 Nginx를 설치했습니다. PHP의 출력을 정적 파일로 캐시하도록 Nginx를 구성하는 데 문제가 있습니다. 나는 Proxy_cache를 사용해 보았지만 분명히 내가 뭔가 잘못하고 있는 것 같습니다.
내 기본 구성은 다음과 같습니다.
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;
}
}
답변1
세트프록시_캐시_경로http{}에서 - 컨텍스트 및 영역과 매개변수 정의
http {
...
proxy_cache_path /tmp/cache/blue blue:100m ...;
proxy_cache_path /tmp/cache/white white:100m ...;
...
}
세트프록시_캐시해당 서버/위치 컨텍스트 및 옵션의 영역/해제
예를 들어 캐시 경로를 전역적으로 정의하고 각 서버/위치에 대해 활성화/비활성화합니다.
location /blue {
proxy_cache blue;
proxy_cache_...
}
location /white {
proxy_cache white;
proxy_cache_...
}
location /red {
proxy_cache off;
proxy_cache_...
}
주의하세요. 캐시된 파일은 바이너리 형식입니다.