当前位置:Gxlcms > PHP教程 > nginx的location正则匹配问题

nginx的location正则匹配问题

时间:2021-07-01 10:21:17 帮助过:177人阅读

回复讨论(解决方案)

rewrite ^/([A-D])([a-zA-Z0-9]{10})/?$ /index.php?a=$1&b=$2 last;

rewrite ^/([A-D])([a-zA-Z0-9]{10})/?$ /index.php?a=$1&b=$2 last;



是在location 里匹配,匹配到了做转发的

下面这个报错了,启动不了
  1. location ^/([A-D])([a-zA-Z0-9]{10})/?$ {
  2. proxy_pass http://127.0.0.1:88/;
  3. proxy_redirect off;
  4. proxy_set_header Host localhost2;
  5. proxy_set_header X-Real-IP $remote_addr;
  6. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  7. proxy_set_header Referer $http_referer;
  8. proxy_set_header Cookie $http_cookie;
  9. proxy_connect_timeout 60;
  10. proxy_read_timeout 600;
  11. proxy_send_timeout 600;
  12. }

location ~ ^/([A-D])([a-zA-Z0-9]{10})/?$

加个~就是正则匹配了

报错信息是什么?
贴出来。。。。

location ~ ^/([A-D])([a-zA-Z0-9]{10})/?$

加个~就是正则匹配了



还是报错,启动不了

正在启动 nginx:nginx: [emerg] pcre_compile() failed: missing ) in "^/([A-D])([a-zA-Z0-9]"

报错信息是什么?
贴出来。。。。



正在启动 nginx:nginx: [emerg] pcre_compile() failed: missing ) in "^/([A-D])([a-zA-Z0-9]"

missing ) in "^/([A-D])([a-zA-Z0-9]"
截断在大括号上了,估计是和后面的代码段大括号混淆,需要转义?或者把{10}直接换成+也可以
我没弄过这个...你看看有什么需要特殊处理的符号

missing ) in "^/([A-D])([a-zA-Z0-9]"
截断在大括号上了,估计是和后面的代码段大括号混淆,需要转义?或者把{10}直接换成+也可以
我没弄过这个...你看看有什么需要特殊处理的符号



也不行

location ^/([A-D])([a-zA-Z0-9]+)/?$ {}
我在我这边的nginx上能启动了

location ^/([A-D])([a-zA-Z0-9]+)/?$ {}
我在我这边的nginx上能启动了



你的对的,是我location下面的代码写错了

最后改成这样的了 "~/[A-D][a-zA-Z0-9]{10}$"

人气教程排行