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

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 ^/e/([a-z0-5]{6})$ /index.php?s=/element/elementInfo/shorttag/$1 last;

修改为

rewrite "^/e/([a-z0-5]{6})$" /index.php?s=/element/elementInfo/shorttag/$1 last;

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


你可能感兴趣的:(nginx配置rewrite时报directive “rewrite” is not terminated by “;”)