我刚刚安装了 nginx,我正在尝试设置我的第一个站点。我正在尝试将 nginx 与 php-fpm 一起使用。nginx 已安装(当我转到我的 ip 时,我会默认欢迎访问 nginx 页面)。
现在我正在尝试运行一个简单的脚本:
<?php
phpinfo();
Run Code Online (Sandbox Code Playgroud)
但是我一直在访问 403 Forbidden 页面。在我的虚拟主机的日志中,我可以看到很多行,例如:
2012/05/18 01:29:45 [error] 4272#0: *1 access forbidden by rule, client: x.170.147.49, server: example.com, request: "GET / HTTP/1.1", host: "example.com"
Run Code Online (Sandbox Code Playgroud)
该文件是/srv/www/test/index.phpnginx 的所有者(我认为777ing 包括文件的完整路径无济于事)。
我已经检查过 nginx 确实nginx/nginx在配置中的用户和组下运行,确实如此。在 nginx.conf 中,我更改了默认配置包含路径,以确保没有其他配置妨碍 ( include /etc/nginx/sites-enabled/)。
我使用的配置看起来像(如果您需要其他配置(php-fpm / nginx.conf),请告诉我):
server {
listen 80;
server_name example.com;
root /srv/www/test;
access_log /var/log/nginx/example-access.log;
error_log /var/log/nginx/example-error.log error;
location ~ /. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~* .(js|css|png|jpg|jpeg|gif|ico|xml|swf|flv|eot|ttf|woff|pdf|xls|htc)$ {
add_header Pragma "public";
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 360d;
}
location ~ /.ht {
deny all;
access_log off;
log_not_found off;
}
location ~ /. {
access_log off;
log_not_found off;
deny all;
}
location ~ ^/(index|frontend_dev|admin|staging).php($|/) {
#rewrite ^/(.*)/$ /$1 permanent;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
index index.php;
try_files $uri /index.php?$args;
}
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*den 23
您的配置故意阻止它:
location ~ /. {
access_log off;
log_not_found off;
deny all;
}
Run Code Online (Sandbox Code Playgroud)
这将匹配斜杠后跟任何类型字符的任何请求;.正则表达式中的字符表示“任何字符”。
我假设您打算检查文字.;那就是这个配置:
location ~ /\. {
Run Code Online (Sandbox Code Playgroud)
如果不是这样,请告诉我!