许多人都可以遇到一个陷阱。下面我们列出,我们常常看到的问题,以及表明如何办理这些问题。在Freenode上的#nginx IRC频道这些接头很频繁。
1、权限
从来不要利用777权限,查察目次的权限
2、root配置
BAD:
server{server_namewww.example.com;location/{root/var/www/nginx-default/;#[...]}location/foo{root/var/www/nginx-default/;#[...]}location/bar{root/var/www/nginx-default/;#[...]}}
GOOD:
server{server_namewww.example.com;root/var/www/nginx-default/;location/{#[...]}location/foo{#[...]}location/bar{#[...]}}3、索引配置
BAD:
http{indexindex.phpindex.htmindex.html;server{server_namewww.example.com;location/{indexindex.phpindex.htmindex.html;#[...]}}server{server_nameexample.com;location/{indexindex.phpindex.htmindex.html;#[...]}location/foo{indexindex.php;#[...]}}}
GOOD:
http{indexindex.phpindex.htmindex.html;server{server_namewww.example.com;location/{#[...]}}server{server_nameexample.com;location/{#[...]}location/foo{#[...]}}}4、Using If
if 是邪恶的 拜见If Is Evil
5、Server Name (If)
BAD:
server{server_nameexample.com*.example.com;if($host~*^www.(.+)){set$raw_domain$1;rewrite^/(.*)$$raw_domain/$1permanent;}#[...]}}
每次都要检测主机头,这是低效的,英国服务器俄罗斯主机,你应该制止,推荐利用下面的
GOOD: