8

expiresPHP によって生成された JavaScript ファイルのヘッダーに問題があります。

Web サイトには 2 種類の JavaScript ファイルがあります。1 つの部分は静的な JavaScript ファイルで、もう 1 つの部分は PHP によって動的に生成されます。

期限切れヘッダーのない conf

ここでは、ファイルexpiresにヘッダーは追加されません.js(すべてのファイルが返されますHTTP 200)

location / {
    try_files  $uri $uri/ /index.php;
}

location ~ \.php$ {
    include  /var/ini/nginx/fastcgi.conf;
    fastcgi_pass  php;
    fastcgi_param  SCRIPT_FILENAME /var/www/index.php;
}

期限切れヘッダーを含む conf

ファイルの場所を追加すると、.js動的に生成されたすべてのファイルが返されますHTTP 404

location / {
    try_files  $uri $uri/ /index.php;
}

location ~ \.php$ {
    include  /var/ini/nginx/fastcgi.conf;
    fastcgi_pass  php;
    fastcgi_param  SCRIPT_FILENAME /var/www/dyndev.dk/public/secure/index.php;
}

location ~ \.(js|css)$ {
    expires 1y;
    add_header Cache-Control "public";
}

ヘッダー付きの静的および動的に生成され.jsたファイルの両方を処理する方法は?expires

動的に生成されたすべての JavaScript ファイルには名前が付けられます*-php.js

ファイル構造

/var/www/public/index.php # All none-static file requests are pointed to index.php
/var/www/public/js/main.js # Static files
/var/www/js-dynamically_generated.php # This file is outside the public www, but is routed by PHP since the file doesn't exists inside the public /js

PHP ルーティング

www.example.com/ -> index.php
www.example.com/js -> static content
www.example.com/js/dynamically_generated-php.js -> js-dynamically_generated.php
4

1 に答える 1