NGINX下载PHP文件而不是显示

NGINX下载PHP文件而不是显示

问题描述:

I'm trying to display index.php and info.php on my NGINX webserver but i cant get it working for some reason, my browser keeps downloading the files instead of displaying them. I tried alot of tutorials but i dont know whats wrong.

OS: Ubuntu 17.10 Server

PHP version: 7.1

cgi.fix_pathinfo is set to 0

www.conf file is default except de cgi.fix_pathinfo

server {
    listen 80 default_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 nginx1.domain.com;

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

    location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
    #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    #location ~ /\.ht {
    #       deny all;
    #}
}

Can someone please help me?

我正在尝试在我的NGINX网络服务器上显示index.php和info.php但我无法让它工作 某些原因,我的浏览器不断下载文件而不是显示它们。 我尝试了很多教程,但我不知道什么是错的。 p>

OS:Ubuntu 17.10服务器 p>

PHP版本:7.1 p> \ n

cgi.fix_pathinfo设置为0 p>

除了de cgi.fix_pathinfo p>

  server {\  n listen 80 default_server; 
 listen [::]:80 default_server; 
 
 
 root / var / www / html; 
 
#如果使用PHP 
索引,请将index.php添加到列表中 index.php index.html index.htm index.nginx-debian.html; 
 
 server_name nginx1.domain.com; 
 
 location / {
 try_files $ uri $ uri / = 404; 
} \  n 
位置〜\ .php $ {
 \ try_files $ uri $ uri / = 404; 
 fastcgi_split_path_info ^(。+ \ .php)(/。+)$; 
 ##注意:你应该有“cgi  .fix_pathinfo = 0;“ 在php.ini 
#
 ##单独使用php5-cgi:
 fastcgi_pass 127.0.0.1:9000; 
 ##使用php5-fpm:
 fastcgi_pass unix:/var/run/php/php7.1  -fpm.sock; 
 fastcgi_index index.php; 
包括fastcgi_params; 
} 
 
 #location~ /\.ht {
 #deny all; 
#} 
} 
  code  >  pre> 
 
 

有人可以帮助我吗? p> div>

Please try this smaller example.

location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        include snippets/fastcgi-php.conf;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

And double check if your php-fpm is running:

sudo systemctl status php7.1-fpm.service