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

来源:互联网 发布:联想固态硬盘优化软件 编辑:程序博客网 时间:2024/06/06 10:54
错误提示:
 
[root@Rekfan 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@Rekfan 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@Rekfan 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
0 0
原创粉丝点击