Wildcard request / location in nginx? -


i have script increments global revision number each deployment of website. number mapped html loads css, javascript , sprite assets. used cache-busting strategy.

e.g <link rel="stylesheet" href="/css/screen_r123.css" type="text/css" />

in apache, rewrite these incrementing urls actual assets this:

rewriterule ^css/screen_r(.*).css$ /css/screen_min.css [l] 

how same in nginx? i'm not sure place regex matching logic.

note: don't want append query ?r=123 end of uri because feels incorrect pass query static asset, plus i'm behind varnish proxy doesn't include queries in cache hashes


here current nginx conf site:

server {   listen 8080;   server_name domain.com www.domain.com   port_in_redirect off;    root /usr/share/nginx/mydomain.com/public;   index index.html index.php;    #set long expiry assets   location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {     expires max;     log_not_found off;   }    location / {     #following line not work intended     rewrite ^/css/screen_r(.*).css$ /css/screen.css last;      # check if file or directory index file exists, else route index.php.     try_files $uri $uri/ /index.php;   }    location ~* \.php$ {          fastcgi_pass   unix:/tmp/php5-fpm.sock;     fastcgi_index  index.php;     fastcgi_param  script_filename $document_root$fastcgi_script_name;     include        fastcgi_params;     fastcgi_param application_env "production";     fastcgi_split_path_info ^(.+.php)(.*)$;   }    add_header "x-ua-compatible" "ie=edge,chrome=1";   add_header cache-control "public max-age=60"; } 

solved. rewrite directives need outside of location block.

this works:

server {   listen 8080;   server_name domain.com www.domain.com;   port_in_redirect off;    rewrite ^/css/screen_r(.*).css$ /css/screen.css last;   ... 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -