正在加载中……
最新消息:欢迎大家访问,导航分类不完善,如果找不到自己想要的文章,可以通过【关键词】来进行搜索,^_^!

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

Linux专题 REKFAN.COM 24029浏览 0评论

更多


错误提示:
 
[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

转载请注明:|REKFAN|系统运维| » [解决方法]nginx: [emerg] directive “rewrite” is not terminated by “;”错误

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址