R
R
Roman Radic2017-09-08 22:11:49
PHP
Roman Radic, 2017-09-08 22:11:49

Nginx + php-fpm file not found why?

Installed nginx + php-fpm, set up a file for nginx and created a rule in it to redirect to index.php:

upstream php-handler {
         server unix:/run/php/php7.0-fpm.sock;
        }

server{
        listen  80;
        server_name  education.clouder.xyz;
        root   /var/www/education/;
        index index.php;

        location / {
                try_files $uri $uri/ =404;
                rewrite ^(.+)$ /index.php?url=$1;

        }

        location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
                fastcgi_pass php-handler;
                fastcgi_intercept_errors on;
        }
}

When I try to open any php file in the browser (for example education.clouder.xyz/index2.php) other than index.php it gives a file not found error . Everything else redirects to index.php just fine. Why is that? Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Michurin, 2017-09-08
@denistu10

Remove upstream
and write in location
Restart nginx and check

V
Vladimir, 2017-09-09
@ipdesign

Try like this:

server{
        listen  80;
        server_name  education.clouder.xyz;
        root   /var/www/education/;
        index index.php;

        location / {
                try_files $uri $uri/ =404;
                rewrite ^(.+)$ /index.php?url=$1;

        }

        location ~ \.php(?:$|/) {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass  127.0.0.1:9000; # listen for a port
                include  /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
                fastcgi_pass php-handler;
                fastcgi_intercept_errors on;
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question