0
這2個nginx指令有什麼區別?nginx:location tilde regex vs path
location ^~ /sub-directory
location /sub-directory
在下面的代碼塊,使用proxy_pass
重定向,如果有差別。
這2個nginx指令有什麼區別?nginx:location tilde regex vs path
location ^~ /sub-directory
location /sub-directory
在下面的代碼塊,使用proxy_pass
重定向,如果有差別。
考慮以下nginx的配置
worker_processes 1;
events {
worker_connections 1024;
}
server {
listen 80;
server_name _;
location ^~ /sub-directory {
echo "^~ /sub-directory";
}
location /sub-director
{
echo "/sub-director";
}
location ~* /sub-* {
echo "~* /sub-*";
}
}
我上面使用泊塢窗容器
sudo docker run -p 80:80 -v $PWD/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf openresty/openresty
跑到現在考慮下面捲曲聲明
$ curl http://192.168.33.100/sub-director/abc
~* /sub.*
$ curl http://192.168.33.100/sub-director/
~* /sub.*
$ curl http://192.168.33.100/sub-director
~* /sub.*
$ curl http://192.168.33.100/sub-directory
^~ /sub-directory
$ curl http://192.168.33.100/sub-directory/
^~ /sub-directory
$ curl http://192.168.33.100/sub-directory/abc
^~ /sub-directory
正如你可以看到我不能任何方式到達下面的位置塊
location /sub-director
{
echo "/sub-director";
}
因爲正則表達式會覆蓋此塊。但我仍然可以達到
location ^~ /sub-directory {
echo "^~ /sub-directory";
}
所以這就是區別。當您使用^~
並且某個位置匹配時,則根本不計算正則表達式基本位置。
http://nginx.org/r/location取決於您擁有的其他位置 –