php-fpm在所有请求中返回“找不到页面”...权限已经检查过

时间:2013-06-05 07:15:03

标签: nginx php

所以我会开始说我对Web服务器很新,这是我第一次配置它。据说网络服务器正在运行,我可以很好地添加网站和文件。但是我现在无法使用任何.php文件。

我目前正在FreeBSD上运行nginx并安装了php-fpm。我知道nginx正确使用php-fpm,但对于任何php文件,我尝试查看我得到的是“找不到文件”。我知道这是来自php-fpm,因为对于任何实际上不存在的文件,nginx给了我一个不同的“找不到文件”页面。

我已经浏览了几个谷歌网页关于这个问题,最常见的解决方案是它对php文件的权限不正确。在这一点上,我不能排除太多,但我已经尝试更改文件和文件夹的权限,包括只打开它们一切都没有成功。

这是我的nginx.conf文件,希望它有所帮助。

user  www www;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include         mime.types;
    index           index.html index.htm index.php
    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     logs/access.log main;  ## Default: off
    sendfile        on;
    tcp_nopush      on;

    ###custom changes
    server_tokens           off;
    client_max_body_size    200M;
    client_body_buffer_size 1M;
    port_in_redirect        off;
    ###

    keepalive_timeout  15;  ## Default: 0

    gzip  on;
    ### More custom changes
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    ###


    server { # simple reverse-proxy
        listen       80;
        server_name  localhost;
        #access_log   logs/mySite1.access.log;

        root /usr/local/www/mySite.com;

        location / {
            try_files $uri $uri/ /index.php;
        }

        # this prevents hidden files (beginning with a period) from being served
        location ~ /\.          { access_log off; log_not_found off; deny all; }

        #error_page  404              /404.html;

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;      
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
    }
}

如果有人对这里发生的事情有任何想法,我们将不胜感激。

2 个答案:

答案 0 :(得分:1)

这可能会帮到你。我使用FPM的套接字​​,所以只需更改为使用IP,但这是我的工作配置:

example.com.conf

server {
    listen      192.168.1.1:80;
    server_name example.com;

    charset utf-8;

    access_log /vhosts/example.com/logs/access_log main;
    error_log  /vhosts/example.com/logs/error_log;

    index index.php;

    root  /vhosts/example.com/public;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        fastcgi_pass  unix:/usr/local/etc/php-fpm/nginx.sock;
        include       fastcgi.conf;
    }

    location ~ \.htaccess {
        deny all;
    }
}

fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
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_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

答案 1 :(得分:0)

我认为您的文件系统上实际上没有目录/scripts。你可能意味着$document_root/scripts。如果你有一个目录/scripts,那么发布带有SCRIPT_FILENAME的php-fpm日志。我认为它是默认记录的,但如果没有,则在配置文件中很好地解释了语法。