转载

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

写了个301重定向的规则,结果报以上错误,原来nginx语法检测特别严格,if和后面括号以及变量等号这些元素都要有空格,所以正确的写法是:
  1. if $host != 'www.59et.com' ){  
  2. rewrite ^(.*)$ http://www.59et.com$1 permanent;  
  3.  
用^代替空格看起来更清晰:
if^(^$host^!=^'www.59et.com'^){
 
反正多打几个空格就是了
[root@59et conf.d]# nginx -t the configuration file /opt/nginx/conf/nginx.conf syntax is ok configuration file /opt/nginx/conf/nginx.conf test is successful [root@59et conf.d]# nginx -s reload [root@59et conf.d]#
正文到此结束
Loading...