首页 > 解决方案 > 为什么 $_GET 不在 nginx 服务器中工作,但在 XAMPP localhost 中工作?

问题描述

我已经尝试了许多 stackoverflow 答案来找到解决方案。但是我的代码在 localhost 上的 xampp 服务器上运行,但在 nginx 上不起作用。我正在缩短链接,但 url 没有重定向。

    <?php 
  include "php/config.php";
  $new_url = "";
  if(isset($_GET)){
    foreach($_GET as $key=>$val){
      $u = mysqli_real_escape_string($conn, $key);
      $new_url = str_replace('/', '', $u);
    }
      $sql = mysqli_query($conn, "SELECT full_url FROM url WHERE shorten_url = '{$new_url}'");
      if(mysqli_num_rows($sql) > 0){
        $sql2 = mysqli_query($conn, "UPDATE url SET clicks = clicks + 1 WHERE shorten_url = '{$new_url}'");
        if($sql2){
            $full_url = mysqli_fetch_assoc($sql);
            echo $full_url['full_url'];
            header("Location:".$full_url['full_url']); 
          }
      }
  }
?>

我还编辑了 nginx 站点可用文件

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

        }

        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
             }

            location ~ /\.ht {
                deny all;
          }

标签: phpnginxnginx-config

解决方案


推荐阅读