解决Nginx访问php文件直接下载

这种情况通常是因为nginx没有将PHP文件交给PHP解释器处理,而是直接返回了文件内容,导致浏览器将其当作下载文件。

解决办法

在nginx服务器中配置这么一段代码,用来解析PHP。

location ~ \.php$ {
        try_files $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/php5-fpm.sock; #反注释
        fastcgi_index index.php; #反注释
        include fastcgi_params; #反注释
#       include snippets/fastcgi-php.conf;
#
#       # With php5-cgi alone:
#       fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
#       fastcgi_pass unix:/var/run/php5-fpm.sock;
}

你可能感兴趣的:(MAC,PHP,nginx,php)