peiyuan1030 发表于 2016-12-28 08:21:50

nginx中重写rewrite的语法错误[emerg] unknown directive

  写了个301重定向的规则,结果报以上错误,原来nginx语法检测特别严格,if和后面括号以及变量等号这些元素都要有空格,所以正确的写法是:

if ( $host != 'www.quxiaoshou.com' ){
rewrite ^(.*)$ http://www.quxiaoshou.com$1 permanent;
}
  用^代替空格看起来更清晰:

if^(^$host^!=^'www.quxiaoshou.com'^){

 
页: [1]
查看完整版本: nginx中重写rewrite的语法错误[emerg] unknown directive