nginx:how 使用别名路由不同的路径
nginx:how use alias route different paths
我要点/m/v2/
,然后是随机路径,比如apc, tcb
等等。到/var/www/app
。但是我的配置显示404
location ~* ^/m/v2/([a-z]+)/(.*)$ {
try_files $uri $uri.html $uri/ @htmlext;
alias /opt/www/app/;
index myInterest.html;
access_log logs/app_v2_access.log main;
}
location @htmlext {
rewrite ^(.*)$ .html last;
}
将 alias
与正则表达式 location
结合使用,您应该在 alias
表达式中构建文件的完整路径。有关详细信息,请参阅 this document。
将 alias
与 try_files
结合使用具有挑战性。有关详细信息,请参阅 this bug report。
您的 $uri.html
和 @htmlext
条款似乎在尝试同样的事情。在我的示例中,使用了 if
块而不是 try_files
语句。请参阅 this caution 关于 if
的用法。
例如:
location ~* ^/m/v2/([a-z]+)/(.*)$ {
alias /opt/www/app/;
index myInterest.html;
access_log logs/app_v2_access.log main;
if (-e $request_filename.html) {
rewrite ^(.*)$ .html last;
}
}
我要点/m/v2/
,然后是随机路径,比如apc, tcb
等等。到/var/www/app
。但是我的配置显示404
location ~* ^/m/v2/([a-z]+)/(.*)$ {
try_files $uri $uri.html $uri/ @htmlext;
alias /opt/www/app/;
index myInterest.html;
access_log logs/app_v2_access.log main;
}
location @htmlext {
rewrite ^(.*)$ .html last;
}
将 alias
与正则表达式 location
结合使用,您应该在 alias
表达式中构建文件的完整路径。有关详细信息,请参阅 this document。
将 alias
与 try_files
结合使用具有挑战性。有关详细信息,请参阅 this bug report。
您的 $uri.html
和 @htmlext
条款似乎在尝试同样的事情。在我的示例中,使用了 if
块而不是 try_files
语句。请参阅 this caution 关于 if
的用法。
例如:
location ~* ^/m/v2/([a-z]+)/(.*)$ {
alias /opt/www/app/;
index myInterest.html;
access_log logs/app_v2_access.log main;
if (-e $request_filename.html) {
rewrite ^(.*)$ .html last;
}
}