0

I'v configured Ngnix server on CentOs 7 and it is working find with html but when I'm trying to open .php file it is downloaded. I'm using Php7.2. Here is my configuration(I'm using 123.123.123.123 instead my real ip):

server {
        listen [::]:80 default_server ipv6only=on;
        listen 123.123.123.123:80 default_server;

        root /var/www/example.com/public_html;
        index index.php index.html;

        server_name 123.123.123.123;

        location / {
                try_files $uri $uri/ =404;
        }

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

So when I'm trying to access to 123.123.123.123/test/index.php I'm geting file download.

How could I force ngnix to execute php files?

0

1 Answer 1

1

You also need fastcgi_pass:

location ~ \.php$ {        
  fastcgi_pass 127.0.0.1:9000;         
  fastcgi_index index.php;         
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        
  include fastcgi_params; 
  }       
Sign up to request clarification or add additional context in comments.

2 Comments

And what ip and port I should set?
Since PHP-FPM runs in the same machine, 127.0.0.1 is correct. The port is by default 9000. See configuration files at /etc/php-fpm.d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.