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