繁体   English   中英

NGINX FASTCGI / PHP-从上游客户端读取响应头时,主脚本未知

[英]NGINX FASTCGI/PHP - Primary script unknown while reading response header from upstream, client

我有一个开发箱,每个用户的主目录中都有一个www文件夹。 NGINX正在从http:// IP地址/ USERNAME托管这些目录。 这很棒。 我想让PHP以相同的方式工作。

/ etc / nginx / sites-available-default:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        #root /usr/share/nginx/html;
        #index index.html index.htm;
        # Make site accessible from http://IP ADDRESS/
        server_name IP ADDRESS;
        #location ~ ^/(.+?)(/.*)?$ {
        location ~ ^/(.+?)(/.*)?$ {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
                alias /home/$1/www$2;
                index  index.html index.htm index.php;
                include /etc/nginx/php.fast.conf;
                autoindex on;
        }

php.fast.conf文件:

location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
#       fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
#       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /home/$1/www$2$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;

}

如您所见,我尝试了一些变种,但似乎继续在日志中收到以下错误:* 1在stderr中发送的FastCGI:“主要脚本未知”,同时从上游客户端读取响应头。

尝试呈现简单的PHP信息页面时,页面显示“找不到文件”

其他信息:服务器= ubuntu 14.x最新的Nginx Digital Ocean Droplet

提前致谢。

server {
        listen 80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name _;

        location ~* \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            try_files $fastcgi_script_name =404;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            set $path_info $fastcgi_path_info;
            fastcgi_param PATH_INFO $path_info;

            fastcgi_index index.php;
            include fastcgi_params;
        }

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location ~* ^/(.+?)/www(/.*|/|)$ {
                root /home;
                index index.php index.html;

                fastcgi_pass unix:/var/run/php5-fpm.sock;

                # regex to split $uri to $fastcgi_script_name and $fastcgi_path
                fastcgi_split_path_info ^(.+\.php)(/.+)$;

                # Check that the PHP script exists before passing it
                try_files $fastcgi_script_name =404;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                # Bypass the fact that try_files resets $fastcgi_path_info
                # see: http://trac.nginx.org/nginx/ticket/321
                set $path_info $fastcgi_path_info;
                fastcgi_param PATH_INFO $path_info;

                fastcgi_index index.php;
                include fastcgi_params;
        }

        location ~* ^/(.+?)(/.*|/|)$ {
                index index.php index.html;
                try_files $uri $uri/ @home;
        }

        location @home {
                rewrite ^/([^/]+?)$ /$1/www/ last;
                rewrite ^/(.+?)(/.*|/)$ /$1/www$2 last;
        }

}

此配置的缺点,不能像/<anything_you_want>/www这样使用URI。

也许有帮助。 但这是怪异的,未优化的丑陋配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM