nginx url 正则匹配v0.1
2021-05-19 本文已影响0人
Go_python_Linux
nginx 正则备忘记录
server {
listen 80;
listen [::]:80;
server_name test.name;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# 精确匹配
location = /google {
rewrite ^ http://google.com;
}
# 前缀匹配
location ^~ /baidu {
rewrite ^ http://baidu.com;
}
# 正则匹配 区分大小写
location ~ /sogou {
rewrite ^ http://sogou.com/;
}
# 正则匹配 不 区分大小写
location ~* /SoGou {
rewrite ^ http://sogou.com/;
}
# 正常匹配 优先级低于前缀匹配 (可使用正则,不区分大小写)
location /biying {
rewrite ^ http://biying.com/;
}
# 全匹配
location / {
root /usr/share/nginx/html;
}
# 别名匹配
error_page 404 = @notfound;
location @notfound {
rewrite ^ http://taobao.com/;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}