Até onde eu entendi, podemos supor que, se houver uma [example.com]
de substring no início da variável $arg_title
, podemos recortá-la com segurança.
Então aqui está a configuração que você precisa:
location ~* /pdf/([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F]+)\.pdf$ {
#First of all we should put pdf path from the request into a variable,
#since $1,$2,$n would contain other data later:
set $hashpath $1/$2/$3/$4/$5/$1$2$3$4$5$6;
#Same applies to hash title:
set $hashtitle $1$2$3$4$5$6;
#Now we try to get the title argument without getting [example.com] in the beginning:
if ( $arg_title ~ "^(\[example\.com\])?(.*)$")
{
#This way if title contained [example.com], it would go to $1 variable, while $2 has our new cleaned title:
set $pdftitle $2;
}
#now we check if title was empty:
if ( $arg_title = '' ) {
#and assign our title that $hashtitle variable we got from the request earlier:
set $pdftitle $hashtitle;
}
#also we check if title has only [example.com] without anything else:
if ( $arg_title = '[example.com]' ) {
set $pdftitle $hashtitle;
}
#After that we can safely put [example.com] in front of our filename, without worrying that there would be a double:
add_header Content-Disposition 'attachment; filename="[example.com]$pdftitle.pdf"';
alias /var/www/example.com/pdf/$hashpath.pdf;
expires 1y;
}
Funciona bem com o nginx 1.9.12 aqui:
com o arquivo atual localizado aqui