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

相关推荐

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

    2023-12-09 00:42:01       34 阅读
  2. PHP解决Safari浏览器下载文件文件名称乱码的问题

    2023-12-09 00:42:01       56 阅读
  3. ubuntu nginx配置密码访问下载

    2023-12-09 00:42:01       54 阅读
  4. Nginx配置文件解释

    2023-12-09 00:42:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-09 00:42:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-09 00:42:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-09 00:42:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-09 00:42:01       20 阅读

热门阅读

  1. React 好用的工具库

    2023-12-09 00:42:01       36 阅读
  2. 关于 React 如何自定义配置 HighCharts tooltip

    2023-12-09 00:42:01       34 阅读
  3. CentOS 7 安装 Nginx

    2023-12-09 00:42:01       36 阅读
  4. 与脾气不太好的领导,相处原则和相处技巧分享

    2023-12-09 00:42:01       33 阅读
  5. flutter布局详解及代码示例(补充)

    2023-12-09 00:42:01       34 阅读
  6. MySQL 错误 1292 是什么?怎么解决?

    2023-12-09 00:42:01       38 阅读
  7. MySQL查看和修改时区

    2023-12-09 00:42:01       39 阅读
  8. 数据结构详解各种算法

    2023-12-09 00:42:01       35 阅读