nginx配置rewrite时报directive “rewrite” is not terminated by “;”

发布时间:2017-06-10 14:42:45编辑:丝画阁阅读(712)

nginx中可以使用rewrite配置url的重定向,rewrite指令可以位于server段,也可以位于location中,配置rewrite后通过/usr/local/nginx/sbin/nginx -t检查配置时,出现如下错误:

nginx: [emerg] directive "rewrite" is not terminated by ";" in /usr/local/nginx/conf/nginx.conf:139
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

解决的办法是把规则段使用引号引起来。例如:

rewrite ^/u_(.{7})\.js$ /action/js.php?i=$1 break;
修改为
rewrite "^/u_(.{7})\.js$" /action/js.php?i=$1 break;
本条可以不用引号
rewrite ^/u_(\d+)\.js$ /action/js.php?i=$1 break;

为什么有些必须要引号,有些又可以省略呢,仔细看第一条规则,里面出现了符号 “{、}”,应该是它造成的,因为配置文件中都是用它来作为配置的段起止标记,所以为了安全起见,最好还是都带上引号。

关键字