鍍金池/ 問(wèn)答/PHP  Linux/ nginx解析php頁(yè)面成空白頁(yè)

nginx解析php頁(yè)面成空白頁(yè)

Nginx無(wú)法解析php頁(yè)面,status為200,錯(cuò)誤日志也什么都沒(méi)有, 圖片描述

但html頁(yè)面能夠順利解析。

cenos7系統(tǒng)版本,Nginx版本為1.14,網(wǎng)上的方法基本都嘗試過(guò)了,在nginx.conf加fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name 沒(méi)用。

我的nginx.conf內(nèi)容:

user  root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}


server {

    listen       8080;
    server_name 127.0.0.1;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    root  /mnt/hgfs/WWW/ParallelForPhp_new/public;
    fastcgi_param   SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    
    location / {
        index  index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    #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/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
    #

    if (!-e $request_filename) {
         rewrite ^/(.*)$ /index.php?/$1 last;
    }


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
     }
}
回答
編輯回答
荒城

location ~ .php$ {

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

}
這是我的配置
然后你要看看你有沒(méi)有啟動(dòng)php-fpm
還有注意你php-fpm.conf文件里面是怎么監(jiān)聽(tīng)的
如果是:listen = 127.0.0.1:9000就沒(méi)有問(wèn)題
如果是:listen = /usr/local/var/php-fpm.sock
你就需要把fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass listen = /usr/local/var/php-fpm.sock

2017年2月23日 20:31