Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 在Nginx上配置缓存css/js文件_File_Caching_Nginx_Ubuntu 14.04 - Fatal编程技术网

File 在Nginx上配置缓存css/js文件

File 在Nginx上配置缓存css/js文件,file,caching,nginx,ubuntu-14.04,File,Caching,Nginx,Ubuntu 14.04,我正在使用Ubuntu 14.04的nginx主机 我的配置文件: server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; # Make site accessible from http://localhost/

我正在使用Ubuntu 14.04的nginx主机

我的配置文件:

  server {

    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name testing.com;



location /site/admin/ {
    alias /usr/share/nginx/html/site/admin/src/;
}

location ~ \.(css|js)$ {
     expires 1y;
     access_log off;
     add_header Cache-Control "public";
}
我有一些错误

[error] 29224#0: *10047 open()     "/usr/share/nginx/html/site/admin/assets/js/jquery.nestable.js" failed (2: No such file or directory) 
实际上,该文件位于:

 /usr/share/nginx/html/site/admin/src/assets/js/jquery.nestable.js
如何设置配置文件?

您的
位置~\(css | js)$
块从服务器块继承
根/usr/share/nginx/html

此外,正则表达式位置块优先于前缀位置块-有关详细信息,请参阅

通过使用
^ ~
修饰符,可以强制
位置/site/admin/
块在同一级别重写正则表达式位置块:

location ^~ /site/admin/ {
    alias /usr/share/nginx/html/site/admin/src/;
}
上面的位置块是前缀位置(而不是正则表达式位置块)。有关详细信息,请参阅

当然,这也意味着以
/site/admin/
开头,以
.css
.js
结尾的URI将不再更改其缓存参数。可以通过添加嵌套位置块来解决此问题,如下所示:

location ^~ /site/admin/ {
    alias /usr/share/nginx/html/site/admin/src/;

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