小编And*_*sky的帖子

nginx PHP文件下载而不是执行

我正在努力实现以下目标。我在域根目录下有主网站。它工作正常。即执行 PHP 文件。一段时间后,我添加了具有基本 HTTP 身份验证的“auth”目录。接下来,我将 PHP 程序上传到“auth”目录,但 PHP 文件正在下载而不是执行。

  • domain.name/test.php -> 执行
  • domain.name/sub/file.php -> 执行
  • domain.name/auth/protected.php -> 下载而不是执行

这是站点可用的配置文件

服务器 {
    字符集 utf-8;

    听 80 default_server;
    听 [::]:80 default_server;

    根 /var/www/html;

    # 如果您使用的是 PHP,请将 index.php 添加到列表中
    index index.php index.html index.htm index.nginx-debian.html;
    server_name xxx.com;

    地点 / {
        # 首先尝试将请求作为文件提供服务,然后
        # 作为目录,然后回退到显示 404。
        # try_files $uri $uri/ =404;
        try_files $uri $uri//index.php?$args;
    }

    位置 ^~ /auth {
        auth_basic "受限内容";
        auth_basic_user_file /var/www/html/auth/.htpasswd;
    }

    位置 ^~ /protected {
        否认一切;
    }

    位置 ~ \.php$ {
        包括片段/fastcgi-php.conf; …

nginx conf

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

conf ×1

nginx ×1