我在迁移服务器时需要在新的服务器上配置好php+nginx环境,但是按照以前的方式配置后发现无法访问页面,查看nginx的错误日志显示:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
在网上找了很多相关的问题答案,一一尝试后仍然无效。
以下是我的nginx配置文件nginx.conf
server {
listen 80;
server_name localhost;
root /var/www/nginx_default/public;
index index.php;
charset utf-8;
#access_log /home/wwwlogs/access.log;
#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 html;
}
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}
location /
{
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/nginx_default/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
}
业精于勤,荒于嬉;行成于思,毁于随。