您的位置:首页 > 运维架构 > Nginx

nginx配置遇到的问题与解决方法(nginx.conf正则)

2016-08-08 22:21 549 查看
在:http://onlyzq.blog.51cto.com/1228/535279 中提到了使用正则表达式对server_name进行配置

但我配置下来,在使用location参数以后会导致:

访问location定义过的文件报404错误,但是能够访问未定义的文件,

经过排查,发现是以下代码问题:

server_name ~^([^.]+)\.([0-9]\.)?(baidu|sina)\.com$;
root  /home/wwwroot/$1/;
access_log  /home/wwwlogs/access_$1.log;


在nginx启动的时候,会被重复赋值,因此可以说,后一个配置会吧前一个配置覆盖.

因此将以上代码修改为

server_name ~^([^.]+)\.([0-9]\.)?(baidu|sina)\.com$;
set $www_root $1;
root  /home/wwwroot/$www_root/;
access_log  /home/wwwlogs/access_$www_root.log;


防止重复赋值导致出错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐