我刚刚安装了nginx,并且正在尝试设置我的第一个站点。我正在尝试将nginx与php-fpm一起使用。已安装nginx(当我转到ip时,将获得默认的欢迎使用nginx页面)。
现在,我正在尝试运行一个简单的脚本:
<?php
phpinfo();
但我一直打到403禁止页面。在我的虚拟主机的日志中,我可以看到很多行,例如:
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"
该文件是/srv/www/test/index.php
nginx的所有者(我777
尝试将包括文件在内的完整路径都删除了)。
我已经检查过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;
}
}