nginx配置指令rewrite的last、break、redirect、permanent参数详解 - 简书 (jianshu.com)
server {
listen 80;
server_name example.com;
set $flag "org";
location /noflag/ {
set $flag "noflag";
rewrite ^/noflag/(.*) /test/$1?capture=$1;
set $flag "rewrite noflag";
echo flag=[$flag];
echo "noflag page";
echo request=[$request];
echo request_uri=[$request_uri];
echo uri=[$uri] args=[$args];
echo document_uri=[$document_uri] query_string=[$query_string];
}
server {
listen 80;
server_name example.com;
root /var/www/html;
location / {
if ($request_uri = /path1) {
rewrite ^ /path2 last;
}
if ($request_uri = /path3) {
# 执行特定操作
}
if ($request_uri ~* "^/path4/.*$") {
# 执行特定操作
}
if ($request_uri ~* "^/path5/(.*)$") {
rewrite ^ /path6/$1 last;
}
# 默认操作
}
}
post 测试
浏览器没办法做 post 请求,除非自己写一个表单。
if ($request_method = POST){
return 405;
}