NGINX下载PHP文件而不是显示

问题描述 投票:1回答:1

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

操作系统:Ubuntu 17.10服务器

PHP版本:7.1

cgi.fix_pathinfo设置为0

除了de cgi.fix_pathinfo之外,www.conf文件是默认的

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

有人可以帮帮我吗?

php linux nginx
1个回答
0
投票

请尝试这个较小的例子。

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

并仔细检查你的php-fpm是否正在运行:

sudo systemctl status php7.1-fpm.service
© www.soinside.com 2019 - 2024. All rights reserved.