Nginx と Apache、proxy_cache をどのように設定するのですか?

Nginx と Apache、proxy_cache をどのように設定するのですか?

Apache のフロントエンド プロキシとして Nginx をインストールしています。Apache は PHP を処理し、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_...


}

注意してください、キャッシュされたファイルはバイナリ形式になります

関連情報