2014-04-14 10:48:01
来 源
kejihao
Nginx
本文介绍解决Nginx服务器配置多站点时filenotfound的错误,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。
配置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;

}

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。