当前位置:首页 > Liunx教程 >

nginx:[emerg] directive “rewrite” is not terminated by “;”错误

发布时间:2018-08-23 20:48:18 作者:佚名 阅读:(245)

错误提示:
 
[root@itbiancheng sbin]# ./nginx -t
nginx: [emerg] directive "rewrite" is not by ";" in /usr/local/nginx/vhost/Rekfan.conf:24
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@itbiancheng sbin]# ./nginx -t
nginx: [emerg] directive "rewrite" is not terminated by ";" in /usr/local/nginx/vhost/Rekfan.conf:25
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
You have new mail in /var/spool/mail/root
 
查看伪静态规则 发现没有问题,最后是以last;结束的,但仍然会报错。
rewrite ^(.*)/list-([0-9]{1,}).html$ $1/index.php?lid=$2 last;
rewrite ^(.*)/file-([0-9]{1,}).html$ $1/index.php?fid=$2 last;
rewrite ^(.*)/article-([0-9]{1,}).html$ $1/index.php?aid=$2 last;
 
错误原因:
 
后来调试发现,这是由于规则里有大括号“{ }”的符号,Nginx误以为这是规则的结尾,产生错误。
 
解决方法:
 
因此,为避免这种情况的发生,需要用双引号把伪静态规则给标识出来,就可以了。
 
更改为如下规则后正常
rewrite "^(.*)/list-([0-9]{1,}).html$" $1/index.php?lid=$2 last;
rewrite "^(.*)/file-([0-9]{1,}).html$" $1/index.php?fid=$2 last;
rewrite "^(.*)/article-([0-9]{1,}).html$" $1/index.php?aid=$2 last;

[root@itbiancheng sbin]# ./nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

欢迎分享转载→ nginx:[emerg] directive “rewrite” is not terminated by “;”错误

© 2015-2019 - 吾爱编程网 版权所有 苏ICP备18033726号-1关于我们 - 网站声明 - 联系我们