考虑下面的Nginxconfiguration文件(64位Linux上的Nginx版本1.2.6):
location / { root html/www.domain.com; } location /image/ { root html/static.domain.com; }
使用这个configuration, html/www.domain.com/index.html提取html/www.domain.com/index.html ; /secure/profile.html从html/www.domain.com/secure/profile.html中选取,而/image/logo.jpeg则从html/static.domain.com/image/logo.jpeg 。
但是,对以下内容的请求会导致错误(可以理解):
/index.html;affiliate=msn /image/logo.jpef~partner=msnbc
什么应该是正确的Nginxconfiguration忽略URL部分,如;affiliate=msn和~partner=msnbc ?
像这样的东西
location / { try_files $uri $uri/index.html =404; } location ~ "(.*)[;~].*" { try_files $1 $1/index.html =404; }
已经改变了configuration如下,以获得所需的行为。
location /image/ { rewrite ^(/image/.*)[\;\,\~].*$ $1 break; root html/static.domain.com; }
请注意,分号必须转义(\;),因为它是Nginxconfiguration文件中的语句分隔符。