nginx子目录 - 主脚本未知

时间:2015-03-23 13:44:42

标签: nginx php

我试图找出为什么我一直收到未找到的文件。

我有一个包含多个目录的目录,其中包含php文件。我不确定如何配置我的conf文件来执行这些文件。

我在错误日志中得到以下内容。

*133 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.8.1, server: 172.17.8.101, request: "GET /design_files/tmpls/podcastSilk/L4_index.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "172.17.8.101:8001"

应用程序的目录结构如下

/tmplbuilder
   /design_files
      /tmpls
        /Folder2
          L4_index.php
        /Folder1
          L3_index.php
   /public
      index.php

这是我的nginx.conf文件。

daemon off;

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log notice;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
    multi_accept on;
}


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;

    client_header_timeout 60;
    send_timeout 160;
    client_max_body_size 50M;
    fastcgi_keep_conn off;

    gzip             on;
    gzip_comp_level  2;
    gzip_min_length  1000;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain application/x-javascript text/xml text/css application/xml;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index  index.php index.html index.htm ;

    server {
        listen 80;
        server_name 172.17.8.101 192.168.254.96;
        root /var/www/tmplbuilder;
        #try_files $uri $uri/ /index.php$uri /index.php?$args;

        location ~* \.(jpg|jpeg|gif|png|html|htm|css|zip|tgz|gz|rar|doc|xls|pdf|ppt|tar|wav|bmp|rtf|swf|flv|txt|xml|docx|xlsx|js)$ {
            try_files $uri $uri/ public$uri public/index.php$uri =404;
            access_log off;
            expires 30d;
        }


        location /design_files/ {
            root /var/www/tmplbuilder/design_files;
            try_files $uri $uri/;
            #root /var/www/tmplbuilder/design_files;
            #autoindex on;
            location ~* \.php$ {
                #try_files $uri $uri/ $document_root$fastcgi_script_name;

                fastcgi_pass   unix:/tmp/php-fpm.sock;
                include fastcgi_params;
                fastcgi_split_path_info       ^(.+\.php)(.*)$;
                #fastcgi_index L4_index.php;
                fastcgi_param   PATH_INFO       $fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
                #return 200 $document_root$uri;
            }
        }

        location /public/{
            #return 200 $uri;
            #alias /var/www/tmplbuilder/public;
            root /var/www/tmplbuilder/public;
            try_files $uri $uri/ /index.php index.php$uri$args;
            # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
            if (!-e $request_filename)
            {
                rewrite ^/(.*)$ /public/index.php?/$1 last;
                    break;
            }


            location ~ \.php$ {
              return 200 $uri;
               fastcgi_pass   unix:/tmp/php-fpm.sock;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               fastcgi_param   PATH_INFO               $fastcgi_path_info;
               include        fastcgi_params;
            }
        }

    }
}

当我运行返回200 $ document_root $ fastcgi_script_name时。我得到了相关文件的相应路径。这是nginx无法找到的路径吗?该文件的权限为755。

1 个答案:

答案 0 :(得分:0)

尝试在正则表达式($ 1)中匹配uri,然后将其作为脚本名称提供给php-fpm。

 location ~ ^(.*\.php)(.*)$ {
   fastcgi_pass   unix:/tmp/php-fpm.sock;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME $document_root/$1;
   fastcgi_param   PATH_INFO $fastcgi_path_info;
   include        fastcgi_params;
 }