当我配置完nginx.conf后,执行 /usr/local/nginx1.7.11/sbin/nginx -t 检查配置文件是否正确时,提示出错:

nginx: [emerg] unknown "server_name="atstest.mytest1.com"" variable
nginx: configuration file /usr/local/nginx1.7.11/conf/nginx.conf test failed

我的nginx.conf配置如下:
server {
                listen 8080;
                server_name atstest.mytest1.com atstest.mytest1.com.cn;
                if ($server_name="atstest.mytest1.com"){
                rewrite ^/(.*) redirect;
                              }
                location / {
                        root  /usr/local/nginx1.7.11/html/;
                        index  index.html index.htm;
                                                }
        }

 最后找到原因,是等号前后没有空格导致,nginx语法还有点古怪,少个空格都不行,
正确写法为 :if ($server_name = "atstest.mytest1.com"){
12-06 10:24
查看更多