nginx,别名,php-fpm =找不到文件


10

我正在尝试使用DAViCal设置nginx。但是,我在日志中收到一个“找不到文件”和“在stderr中发送了一个FastCGI:“主脚本未知”。我的别名似乎有问题,但我确定无法解决。

我的虚拟主机:

server {
listen   80; ## listen for ipv4; this line is default and implied
listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

root /var/www-data;
index index.html index.htm index.shtml index.php;

# Make site accessible from http://localhost/
server_name just.a.server;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.html;
    ssi on;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
    #try_files  $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
}

location /kalender {
    alias  /usr/share/davical/htdocs;
}

}

我的fastcgi_params

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_FILENAME     $request_filename;
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   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;

fastcgi_param   HTTPS           $https;

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

期待您的答复。


htdocs是777 btw-
马丁

Answers:


20

解决它。原来,您必须在每个位置块下都包含php位。

location /calender {
    alias  /usr/share/davical/htdocs;

        location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        }

}

太棒了,有一种方法可以“包含”此内容,否则您需要为每个位置更改php内容!
Sandro Antonucci 2014年

这不适用于每个操作系统和每个版本。这一切都取决于fastcgi_param SCRIPT_FILENAME和事实是它在设置fastcgi_paramsfastcgi.conf看到这个
hrvoj3e

1

我发现将php匹配块移到我的根位置块上方就可以了。

location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_intercept_errors on;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index  index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location / {
    root /Users/YOU/Projects/PROJECT;
}

3
这对别名有用吗?这不能回答原始问题。
杰弗里2015年

1
不相关。Nginx总是首先尝试正则表达式位置块。
Z. Zlatev 2015年

@Geoffrey是的,这确实适用于别名
icc97
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.