因此,当我尝试点击时,nginx 会给我一个 403 Forbidden 错误页面http://mayall.syniq.co.uk应该会吐出一个向 Rik Mayall 致敬的页面,就像http://byrne.syniq.co.uk(您很快就能猜出我的命名方案:))。
namei -l /www/vhosts/mayall.syniq.co.uk/public/index.html 产生以下内容:
f: /www/vhosts/mayall.syniq.co.uk/public/index.html
drwxr-xr-x root root /
drwxr-xr-x www-data www-data www
drwxr-xr-x www-data www-data vhosts
drwxr-xr-x www-data www-data mayall.syniq.co.uk
drwxr-xr-x www-data www-data public
-rw-r--r-- www-data www-data index.html
所以这不是权限问题。我的 vhost 配置如下:
server {
listen *:80;
listen [::]:80;
server_name mayall.syniq.co.uk;
# Character Set
charset utf-8;
# Logs
access_log /www/vhosts/mayall.syniq.co.uk/logs/access_log.nginx;
error_log /www/vhosts/mayall.syniq.co.uk/logs/error_log.nginx;
# Directory Indexes
index index.html index.htm;
root /www/vhosts/mayall.syniq.co.uk/public;
location / {
try_files $uri $uri/ =404;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
# Block access to .htaccess
location ~ \.ht {
deny all;
}
}
日志中出现的内容如下:
2014/10/01 18:58:20 [error] 20957#0: *1 access forbidden by rule, client: 31.49.162.112, server: mayall.syniq.co.uk, request: "GET / HTTP/1.1", host: "mayall.syniq.co.uk"
2014/10/01 18:58:30 [error] 20957#0: *1 access forbidden by rule, client: 31.49.162.112, server: mayall.syniq.co.uk, request: "GET /index.html HTTP/1.1", host: "mayall.syniq.co.uk"
有任何想法吗?
答案1
因此,freenode 上 #nginx 中的一个人向我指出了这一点,但我猜他不想在这里发布答案。
我收到 403 的原因是因为该块与inlocation ~ \.ht
匹配,因此错误地阻止了请求。.ht
index.html
/
修复方法很简单,只需在 . 前添加一个,如下所示:
location ~ /\.ht {
deny all;
}