Nginx别名和php-fastcgi:没有指定输入文件

时间:2013-12-01 23:31:30

标签: php nginx fastcgi

我的域名配置如下:

server {
    listen       80;
    root   /var/www/domains/somedomain/root;

    location = /service/alias/ {
        alias /var/www/service/alias/;
        index index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

当有人请求http://example.com/service/alias时,我想在index.php中执行/var/www/service/alias/文件。我尝试了很多变化(将FastCGI参数放在该位置并提供index.php脚本的完整路径),但我不断从php-fastcgi获得“未指定输入文件”错误。

任何人都知道我做错了什么?或者至少我怎么能记录php-fastcgi的完整错误?

1 个答案:

答案 0 :(得分:0)

indexbetter in a server scope因为那么所有其他位置都将保留该值,特别是如果它们是相同的多个索引,并且我喜欢我的php块尽可能小,因为大多数其他选项已经包含在fastcgi_params中,我也相信fastcgi_pass应该直接传递给http://而不是IP,所以请尝试使用此版本并告诉我它是否适合您。

server {
  listen 80;
  # added a server name, unless it's a catch all virtual host
  # then you better use `default_server` with `listen`
  server_name example.com;
  root /var/www/domains/somedomain/root;
  # index moved here
  index index.php;
  location = /service/alias/ {
    # why `=` ? I would remove it unless there's a purpose
    # index removed from here
    alias /var/www/service/alias/;
  }
  location ~* \.php$ {
    #removed all other options
    include fastcgi_params;
    # added `http` before `127.0.0.1`
    fastcgi_pass http://127.0.0.1:9000;
  }
}