【问题标题】:NGINX downloads PHP file instead of showingNGINX 下载 PHP 文件而不是显示
【发布时间】:2018-01-19 06:32:17
【问题描述】:

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

操作系统:Ubuntu 17.10 服务器

PHP 版本:7.1

cgi.fix_pathinfo 设置为 0

www.conf 文件是默认的,除了 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;
    #}
}

有人可以帮帮我吗?

【问题讨论】:

    标签: php linux nginx


    【解决方案1】:

    请试试这个小例子。

    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
    

    【讨论】:

    • 您好,感谢您的意见。出于某种原因,我的虚拟主机配置在重新启动后消失了。我插入了你的配置,它成功了!非常感谢!
    猜你喜欢
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2014-10-17
    • 2019-07-21
    • 1970-01-01
    相关资源
    最近更新 更多