/ 中存储网

解决Nginx服务器配置多站点时file not found的错误

2014-04-14 10:48:01 来源:kejihao
配置nginx + php5-fpm

最初的nginx的配置文件

server {

listen 80; ## listen for ipv4; this line is default and implied

#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

# Make site accessible from http://localhost/

server_name localhost;

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {

access_log off;

expires 30d;

root /var/www;

}

location / {

root /var/www;

index index.php;

# First attempt to serve request as file, then

# as directory, then fall back to index.html

try_files $uri $uri/ /index.php;

}

#location /doc/ {

# alias /usr/share/doc/;

# autoindex on;

# allow 127.0.0.1;

# deny all;

#}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

#error_page 500 502 503 504 /50x.html;

#location = /50x.html {

# root /usr/share/nginx/www;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ .php.*$ {

fastcgi_pass backend;

fastcgi_index index.php;

set $real_script_name $fastcgi_script_name;

set $path_info "";

if ($fastcgi_script_name ~ "^(.+?.php)(/.+)") {

set $real_script_name $1;

set $path_info $2;

}

fastcgi_param PATH_INFO $path_info;

fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

fastcgi_param SCRIPT_NAME $real_script_name;

include /etc/nginx/fastcgi_params;

#fastcgi_param QUERY_STRING $query_string;

#fastcgi_param REQUEST_METHOD $request_method;

#fastcgi_param CONTENT_TYPE $content_type;

#fastcgi_param CONTENT_LENGTH $content_length;

#fastcgi_intercept_errors on;

#fastcgi_ignore_client_abort off;

#fastcgi_connect_timeout 36000;

#fastcgi_send_timeout 36000;

#fastcgi_read_timeout 36000;

#fastcgi_buffer_size 128k;

#fastcgi_buffers 4 256k;

#fastcgi_busy_buffers_size 256k;

#fastcgi_temp_file_write_size 256k;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

location ~ /.ht {

deny all;

}

}

upstream backend {

server 127.0.0.1:9000;

}

上面的配置文件配置下来,请求index.php文件产生file not found的错误,最终确定确定导致这个错误的原因是,在下面的配置部分要加上红色部分,问题解决

location ~ .php.*$ {

root /var/www;

fastcgi_pass backend;

fastcgi_index index.php;

set $real_script_name $fastcgi_script_name;

set $path_info "";

if ($fastcgi_script_name ~ "^(.+?.php)(/.+)") {

set $real_script_name $1;

set $path_info $2;

}

fastcgi_param PATH_INFO $path_info;

fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;

fastcgi_param SCRIPT_NAME $real_script_name;

include /etc/nginx/fastcgi_params;

#fastcgi_param QUERY_STRING $query_string;

#fastcgi_param REQUEST_METHOD $request_method;

#fastcgi_param CONTENT_TYPE $content_type;

#fastcgi_param CONTENT_LENGTH $content_length;

#fastcgi_intercept_errors on;

#fastcgi_ignore_client_abort off;

#fastcgi_connect_timeout 36000;

#fastcgi_send_timeout 36000;

#fastcgi_read_timeout 36000;

#fastcgi_buffer_size 128k;

#fastcgi_buffers 4 256k;

#fastcgi_busy_buffers_size 256k;

#fastcgi_temp_file_write_size 256k;

}