简体   繁体   English

Nginx php文件正在下载而不是执行

[英]Nginx php files are downloading instead of execute

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. 我已经在CentOs 7上配置了Ngnix服务器,并且正在使用html查找,但是当我尝试打开.php文件时,它已下载。 I'm using Php7.2. 我正在使用Php7.2。 Here is my configuration(I'm using 123.123.123.123 instead my real ip): 这是我的配置(我使用的是123.123.123.123而不是我的真实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. 因此,当我尝试访问123.123.123.123/test/index.php时,我正在下载文件。

How could I force ngnix to execute php files? 我怎么能强迫ngnix执行php文件?

You also need fastcgi_pass: 您还需要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; 
  }       

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

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