nginx和index.php下载

时间:2017-08-19 16:08:31

标签: php nginx php-7.1

我刚刚在Ubuntu 16.04上安装了PHP 7.1-fpm的Nginx,我遇到了问题。当我想访问例如http://example.dev时,它会下载 index.php而不是显示主页,但例如http://example.dev/registration效果很好。

这是我的nginx配置:

server {
    listen 80;
    listen [::]:80;

    root /var/www/example/www;

    index index.php index.html;

    server_name example.dev;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        include fastcgi_params;
    }

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

感谢您的回答。

1 个答案:

答案 0 :(得分:4)

有时它可以像清除浏览器缓存一样简单。如果有一些配置错误并且确实正在下载文件,则在修复配置后,需要告知浏览器停止使用缓存下载。

在浏览器中尝试 Ctrl + Shift + R

(来自:https://askubuntu.com/questions/460710/why-is-the-index-php-downloaded-instead-of-rendered-by-nginx