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

错误提示:
 
[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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值