简体   繁体   中英

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

I have a development box that each user has a www folder in the home dir. NGINX is hosting those dirs from http://IP ADDRESS/USERNAME. And this works great. I want to get PHP working in the same fashion.

/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 file:

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;

}

As you can see I have tried a few variations but seem to continue to receive the following error in the log: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client.

When attempting to render a simple PHP info page The page displays "file not found"

Other info: Server = ubuntu 14.x Latest Nginx Digital Ocean Droplet

Thanks in advance.

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;
        }

}

The cons of this config, you can't use URI like /<anything_you_want>/www .

Maybe it helps. But it's weird, non-optimized and ugly config.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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