Menu Home

关于mac 下面配置nginx和php出现Primary script unknown错误问题

通过brew安装nginx、php和mysql都是通过

brew install nginx
brew tap homebrew/homebrew-php
brew install php
brew install mysql

这样下来,没有什么问题,下面是nginx.conf 默认关于php的配置,我就copy到server里面

 location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     include        fastcgi_params;
}         

但是很快error_log里面出现下面错误,浏览器显示file not found

*1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: api.tmp.cn, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9898"

最开始我以为是端口和mac 系统的默认端口冲突,我就换了一个端口依然问题存在。
后来网上试过各种办法后来发现都不行。
最后找到一篇英文的关于 location ~ \.php$ { 里面使用了root ,我在server 也设置了root 这两个冲突,最后我 location ~ \.php$ {里面的root 去掉,就好了
完整站点配置如下:
“`
server {
listen 8080;
server_name api.tmp.cn;

    root /Users/knowthis/Desktop/public;
    index index.html index.php;

    #charset koi8-r;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    #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;
    }

    # 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           html;
       fastcgi_pass   127.0.0.1:9898;
       fastcgi_index  index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include        fastcgi_params;
    }
    access_log /Users/knowthis/logs/access.log;
}

Categories: code

knowthis

发表评论

电子邮件地址不会被公开。 必填项已用*标注