0

所以我会开始说我对 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;
        }
    }
}

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

4

2 回答 2

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;
于 2013-06-06T20:47:19.180 回答
0

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

于 2013-06-07T20:11:23.993 回答