记一次Nginx-Primary script unknown的报错解决

1

报错:

[error] 12691#0: *6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.168.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.168.133"

在Nginx的conf中遭到定义脚本文件的地方:

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

修改成如下方式($document_root):

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

$document_root 代表当前请求在root指令中指定的值:

location / {
   root   /usr/local/nginx/html;
   index  index.php index.html index.htm;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

上面配置中的$document_root就是针对/usr/local/nginx/html目录下的php文件进行解析。

参考

  1. http://www.jb51.net/article/47916.htm

你可能感兴趣的

学想有成 · 2016-10-15

直接把我的nginx配置文件给你看看吧
server

{
    listen          80;
    server_name     www.tp.com;
    access_log      /data1/logs/tp_access.log myformat;
    index index.html index.htm index.php;
    root    /datao/htdocs/thinkphp;

    location ~ \.php
    {
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;
            include      fastcgi_params;
            set $path_info "";
            set $real_script_name $fastcgi_script_name;
            if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                    set $real_script_name $1;
                    set $path_info $2;
            }
            fastcgi_param SCRIPT_FILENAME /data0/htdocs/thinkphp/$real_script_name;
            fastcgi_param SCRIPT_NAME $real_script_name;
            fastcgi_param PATH_INFO $path_info;
    }               
} 

其中/data0/htdocs/thinkphp为你项目根目录路径

回复

asins · 10月12日

我使用Centos 8时也遇到上面的错误,主要是 SELINUX安全机制导致的问题

# ls -alZ 可以查看到目录的状态
drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_content_t:s0 www

# 需要将上面的`httpd_sys_content_t` 更换为 `httpd_rw_content_t`
drwxrwxrwx. ec2-user root system_u:object_r:httpd_sys_rw_content_t:s0 www

# 可以使用下面的命令操作:
chcon -R -t httpd_sys_rw_content_t /www

回复

载入中...